5. Finally be ready to get I2C data from I2C bus system as a slave device by configuring the
I2C interrupt enable bit, the I2C block enable bit, and the ACK enable bit of the I2CMR
register.
I2CMR = IICEN+INTEN+ACKEN; // I2C interrupt enable
14.7.2 I2C interrupt service
I2C interrupt service is used for the next management action and the data load/read from the I2C
block after I2C H/W block operation (as I2C Master/ Slave device). Because the I2C block processes
the I2C data in a byte unit when receiving or writing, the I2C block makes the I2C interrupt for the next
action of the I2C block. When the interrupt occurs, the I2C block serves for the state of I2C bus and
stores the operation result in the I2CSR register. Interrupt service looks both registers of the I2CMR
and the I2CSR, and does the next steps (such as saving a data from I2CDR, loading a data to I2CDR,
making STOP condition or Re-start condition, and so on).
The I2C Interrupt occurs when the following cases are finished:
1. As an I2C master device,
— Sending a byte on I2CDR register after setting Start bit. ( GCALL interrupt )
— Sending a byte on I2CDR register after write to I2CSR. ( TEND interrupt )
— Receiving a byte on I2CDR after write to I2CSR ( TEND interrupt )
— Occurring an arbitration loss ( MLOST interrupt )
— Detecting Stop condition ( STOP interrupt )
2. As an I2C slave device,
— Getting start condition and same device address from a Master ( SSEL interrupt )
— Sending a byte on I2CDR register after write to I2CSR. ( TEND interrupt )
— Receiving a byte on I2CDR after write to I2CSR ( TEND interrupt )
— Detecting Stop condition ( STOP interrupt )
Depending on the above results, the I2C service provides services such as reading/writing data
from/to I2CDR, generating STOP condition, making the next I2C block action by writing a data to
I2CSR register. Bus arbitration of the I2C block processes from I2C bus start condition to the last data
of I2C data frame. During arbitration loss (MLOST interrupt), the I2C interrupt service makes I2C
block Reset for bus free.