RuH_iranga
Junior Member level 3
Dear all
I m trying to communicate two 16f877 PICs with SPI protocol. And USART is used to display the received data from the slave. But my program is not working. I used variable Y=7 in master and send it to slave and then read it from USART. here is my code.
Master
Slave
Please could anyone help me, I can not identify what is wrong with my code. I used MikroC compiler.
Thank you.
I m trying to communicate two 16f877 PICs with SPI protocol. And USART is used to display the received data from the slave. But my program is not working. I used variable Y=7 in master and send it to slave and then read it from USART. here is my code.
Master
Code:
// code for spi master
void main()
{
trisc.f3=0;
trisc.f4=1;
trisc.f5=0;
trisa.f2=0;
porta.f2=1;
Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_END, CLK_IDLE_LOW, LOW_2_HIGH);
while(1)
{
int y=7 ;
Spi_Write(y);
porta.f2=0;
}
}
Slave
Code:
// code for spi slave
void main()
{
unsigned int buffer, gdata =0;
buffer=0;
trisa.f5=1;
trisc.f4=1;
trisc.f5=0;
trisc.f3=1;
Usart_Init(2400);
Spi_Init_Advanced(SLAVE_SS_ENABLE, DATA_SAMPLE_MIDDLE, CLK_IDLE_LOW, LOW_2_HIGH);
while(1)
{
gdata=Spi_Read(buffer);
Usart_Write(gdata);
}
}
Please could anyone help me, I can not identify what is wrong with my code. I used MikroC compiler.
Thank you.