![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
unexpected output during SPI communication |
Posted: Wed Dec 21, 2011 3:55 am |
|
|
i developed the following coding.
what i wanted:
two LEDs at D6, D7 has to blink thrice each on after the other.
then both LEDs blink thrice at the same time....
then it has to settle down at both "GLOW"...
What i got:
the above i got... but the code runs indefinitely without stopping...
in other words: the output gets repeated continuously as if it is in while(1) loop..
doubts:
whether i need to work on its SSPCON?????
note:
i have used D port for SPI communication....
having outputs at D port and spi at the same D port will cause any prob?
MASTER:
Code: | #include <18f4431.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#fuses SSP_RD
#use delay(clock=20000000)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
void main()
{
int a,b,c,d;
setup_spi(SPI_MASTER | SPI_MODE_1 | SPI_CLK_DIV_64);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
for(b=0;b<3;b++)
{
a=0x80;
spi_write(a);
delay_ms(1000);
a=0x81;
spi_write(a);
delay_ms(1000);
}
for(b=0;b<3;b++)
{
a=0x82;
spi_write(a);
delay_ms(1000);
a=0x83;
spi_write(a);
delay_ms(1000);
}
a=0x82;
spi_write(a);
} |
SLAVE:
Code: | #include <18f4431.h>
#use delay(clock=20000000)
#fuses HS,NOWDT,NOLVP,NOPROTECT
#fuses SSP_RD
int val1, val2,i,check;
#int_SSP
SSP_isr()
{
val1 = spi_read();
if(val1==0x80)
{
output_bit(PIN_D6,1);
output_bit(PIN_D7,0);
}
if(val1==0x81)
{
output_bit(PIN_D6,0);
output_bit(PIN_D7,1);
}
if(val1==0x82)
{
output_bit(PIN_D6,1);
output_bit(PIN_D7,1);
}
if(val1==0x83)
{
output_bit(PIN_D6,0);
output_bit(PIN_D7,0);
}
}
void main()
{
setup_spi(SPI_SLAVE | SPI_L_TO_H|SPI_SS_DISABLED);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
while(1);
} |
THANKS IN ADVANCE.......
Last edited by gokulrred on Wed Dec 21, 2011 3:58 am; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Wed Dec 21, 2011 4:25 am |
|
|
You must _never_, repeat _never_ have an interrupt fully enabled (both it and global enabled), without a handler.
Doing so will result in the code looping back to an unexpected location, and may cause anything to happen.
You also don't generally want/need INT_SSP on a master device.
INT_SSP is triggered whenever a byte arrives in the SSP buffer. Since this only happens when the master has sent a byte, it knows already that a byte is there, and the interrupt is 99% pointless.
Get rid of enabling INT_SSP on your master,and see if things improve....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
gokulrred
Joined: 22 Nov 2011 Posts: 32 Location: puducherry
|
|
Posted: Wed Dec 21, 2011 4:52 am |
|
|
EXTRAORDINARY ............
AMAZZZZIIIINGGGGGGGGGGGGGGG.....
THE PROB SOLVED.........
ITS GETTING EXECUTED ONLY ONCE...
THANK U VERY MUCH TTELMAH....... |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|