I'm using a ATtiny817 and want to read data from a sensor via SPI protocol (3 bytes from a AS5311). This works nice. The ATtiny817 also acts as I²C slave and data is read after the MCU signals new data by sending a falling flank on the pin (PIN_FRAME_READY).
This works nicely for a while until suddenly the SPI peripheral stops setting the receive interrupt flag (SPI_RXCIF in SPI0.INTFLAGS). This might happen after hundred SPI reads or after thousands of SPI reads. In error case still data can be send out, but the interrupt flag is not set. I see no difference in the SPI registers for the working and for the non-working case. I tried to bring the RXCIF back by deactivating and reactivating all ISR and by writing all SPI configuration registers to zero and setting them new. There was no effect on the RXCIF at the next transfer.
I have observed this only in combination with I²C slave transfers. Therefore I can't further simplify my example code.
Description of the code:
- each millisecond the RTC sets the periodic interrupt flag and this is tested in the main loop.
- - SPI gets activated and the chip select is activated. I push zeros to SPI0.DATA as there are only bytes to read. Here I'm incrementing the number of started SPI transfers (spiStarted).
- - In the SPI ISR a subsequend byte transfer is triggered. If the buffer is full (3 bytes) a GPIOR flag is set indicating that the transfer is completed (FLAG_SPI_COMPLETED).
- - A completed SPI transfer will lead to a increment of the spiEnded variable.
- each 10 milliseconds the I²C send buffer is filled with the current value of spiStarted and spiEnded
- - A transient on a pin (PIN_FRAME_READY) signals new data, which is then read by the I²C master. After this the pin is cleared again.
What do I observe:
- After a reset the I²C master reads increasing numbers (spiStarted and spiEnded). After a random time the spiEnded is stalled while the spiStarted is still running.
- A logic analyzer on the SPI bus shows reads of three bytes. After the error occured there are only transfers of two bytes.
I tried to remove irrelevant code and keep explaining sections. Therefore there are some unhandled conditions where I see no connection to the error.
Do you have any idea why the interrupt flag is not set after a SPI byte write?
Thanks a lot.