Re: Please help with most basic c code for spi slave read of pic16f690 to pic16f690
There are no config bit settings - default is external RC oscillator, but you set IRCF bits to divide internal oscillator by 4 (2MHz) but comment says 4MHz.
Main problem is spi_write and spi_read never check the BF bit.
spi_write should check that BF=0 before writing the next byte to prevent collisions. Clearing the WCOL bit is not sufficient.
spi_read should check that BF=1 to see if data has been received. Otherwise it just reads whatever garbage is in the shift register.
Also, with SPI it's best to use chip select (SS) so ensure synchronization between tx and rx.
Lots of errors in comments not matching the code.
Can't remember. I've slept since then - Mark