RuH_iranga
Junior Member level 3
Hi all
I am trying to communicate two 16f877a PICs via SPI. But there is a problem. Simply the master write integer 3 into Slave, slave read it and check that value is greater than int 7. If Yes it blink 2 LEDs on RB6 and RB7, else RB6 LED is on.
two codes work correctly on PROTEUS simulator. But in real arrangement, If I send value larger than 7 it blink correctly and some times when I powered two microcontrollers it flash only RB6 as well. Please help me to find where the mistake.
my code
MASTER
SLAVE
Please help me to operate this correctly.
Thank you!
I am trying to communicate two 16f877a PICs via SPI. But there is a problem. Simply the master write integer 3 into Slave, slave read it and check that value is greater than int 7. If Yes it blink 2 LEDs on RB6 and RB7, else RB6 LED is on.
two codes work correctly on PROTEUS simulator. But in real arrangement, If I send value larger than 7 it blink correctly and some times when I powered two microcontrollers it flash only RB6 as well. Please help me to find where the mistake.
my code
MASTER
Code:
// code for spi master
int i;
void main()
{
trisc.f3=0;
trisc.f4=1;
trisc.f5=0;
trisa.f2=0;
porta.f2=1;
delay_ms(10);
porta.f2=0;
Spi_Init();
while(1)
{
//int y=7;
Spi_Write(3);
portc.f3=0;
}
}
SLAVE
Code:
// code for spi slave
void main()
{
unsigned int buffer, gdata =0;
int c=7;
trisb.f7=0;
trisb.f6=0;
trisa.f5=1;
trisc.f4=1;
trisc.f5=0;
trisc.f3=1;
Spi_Init();
while(1)
{
if(Spi_Read(buffer)>=7)
{
portb.f7=1;
portb.f6=0;
Delay_ms(70);
portb.f7=0;
portb.f6=1;
delay_ms(70);
}
else portb.f7=0;
portc.f3=0;
}
}
Please help me to operate this correctly.
Thank you!
Last edited: