Hi everybody, I've created a sketch to do some SPI communications as a slave device and it works pretty reliably, however I am trying to code some error detection/correction now to make it even more reliable. The device is a slave and the master clocks in the data.
I am trying to solve the possible scenario where a bit is missed and my sketch is waiting to have the CLK line clock in data my sketch is trying to send. If the master is not expecting data at that moment the CLK signal will never happen and my sketch will hang, waiting for the CLK line to clock in data it has for the master.
I know in "true" SPI, the SS pin identifies if there is data to be received or not. The setup I'm working with is not "classic" SPI; I am talking to a Kenwood car radio's SPI bus. It has additional request lines for the master and slave, and when one goes low the other goes low to accept and then it clocks in 5 bytes; the 5th byte contains a value which identifies how many more bytes are available. So it is SPI with a twist.
I suppose I could try checking to see that the radio's request line is still low before sending or receiving each byte, but thought it would be more elegant and foolproof/errorproof if SPI.TRANSFER supported some kind of timeout and/or errorlevel returning. I can't use an interrupt to check every 5 seconds because I'm sure the SPI.TRANSFER routines disable interrupts while attempting to transfer data.
Does anyone have any ideas, or know of a way I could try to achieve this?
Thanks for any help from Arduino veterans