sresam89
Member level 2
hi all
i am trying to implement spi communication between two 16f877a.
am giving my CCS code below
the code is fine and is transmitting perfectly. checked using proteus.also verified using some hard way(mentioned later).
this receiver is receiving initially(soon after reset at any point of time) a single character only and halts indefinitely at "waiting" for SSPIF(also tried switching it to BF). the transmitter is sending all the characters mentioned in the program(verified using reset @ slave Before every Tx from Master)
i am trying to implement spi communication between two 16f877a.
am giving my CCS code below
Code:
for master
void main()
{
TRISC=0x10;//SCK is output (Master), SDI is input,
TRISA=0x00;//Slave Select Bit
ADCON1=0x06;
SSPSTAT=0x40;//Mode 1,1 SPI, middle of output time sampling
SSPCON=0x31;//Mode 1,1 SPI Master, 1/16 Tosc bit, SSP is on
SSPIF=0;
WCOL=0;
SSPBUF=0;
lcd_init();
do{
i=0;
ss=0;//also tried always tying Slave SS pin to gnd instead of switching
lcd_putc("\fDATA TRANSMIT\n");delay_ms(2000);
while(wcol);
SSPBUF='b';
while(!SSPIF);
SSPIF=0;
ss=1;//also tried always tying Slave SS pin to gnd instead of switching
printf(lcd_putc,"\fDATA done:1 %C",SSPBUF); delay_ms(3000);
ss=0;//also tried always tying Slave SS pin to gnd instead of switching
lcd_putc("\fDATA TRANSMIT\n");delay_ms(2000);
while(wcol);
SSPBUF='a';
while(!SSPIF);
SSPIF=0;
ss=1;//also tried always tying Slave SS pin to gnd instead of switching
lcd_putc("\fDATA done:2"); delay_ms(3000);
}while(1);
}
the code is fine and is transmitting perfectly. checked using proteus.also verified using some hard way(mentioned later).
Code:
for salve
void main()
{
int8 i=0;
TRISC=0x18;//SCK is input (Slave), SDI is input,SDO is output, all others output
TRISA=0X10;//SLAVE Select Bit
ADCON1=0x06;
SSPSTAT=0x40;//Mode 1,1 SPI, middle of output time sampling
SSPCON=0x34;//SPI Slave Mode(SS bit controlled), 1/16 Tosc bit, SSP is on
SSPBUF=0;
SSPIF=0;
lcd_init();
while(1){
lcd_putc("\fwaiting");
while((BF==0));
SSPIF=0;
printf(lcd_putc," :%c",SSPBUF);
lcd_putc("\ndata");DELAY_MS(500);
}
}
this receiver is receiving initially(soon after reset at any point of time) a single character only and halts indefinitely at "waiting" for SSPIF(also tried switching it to BF). the transmitter is sending all the characters mentioned in the program(verified using reset @ slave Before every Tx from Master)