Hi,
I have currently implemented the code used in the I2C_EEPROM example that utilizes the interrupt state machine to drive the I2C bus. I have, however, modified it not to use the FIFO. Currently the code works just fine sending and receiving data to an EEPROM with the following exception: If a NACK is received from the EEPROM in the middle of a data write, the current transfer will gracefully terminate, however, the next transfer has an unwanted byte. Here's how it is playing out:
(1) Set start bit flag to start transfer.
(2) Processor sends start bit and outputs slave address
(3) Transmit ready interrupt occurs and we stuff next byte into I2CDXR in which the CPU copies to I2CXSR.
(4) CPU starts sending byte in I2CXSR
(5) Another transmit ready interrupt occurs and we again stuff next byte into I2CDXR in which the CPU copies to I2CXSR when ready.
(6) A NACK interrupt occurs because the previous I2CDXR stuffed byte (i.e. the one currently be transmitted) has been NACKED. We Force a stop bit and clear the NACK bit in I2CSTR.
(7) A stop condition detected interrupt occurs to signify end of transfer.
The above all works well, the problem comes when the next transfer is initiated. Once we initiate another transfer the following happens on the bus:
(1) Start bit occurs correctly
(2) slave address sent correctly
(3) The last byte we stuffed into I2CDXR from the last transfer gets dumped on the bus, obviously not want we want. So how do we clear or empty the I2CXSR/I2CDSR register before we start a new transfer upon receiving a NACK?
Thanks,
Dan