36.3.14.2 Condition-Specific Interrupts
In addition to the high-level interrupts, module hardware provides several condition-specific interrupts.
The I2C Peripheral Interrupt Register (I2CxPIR) contains the following interrupt flag bits:
- CNTIF: Byte Count Interrupt Flag
- ACKTIF: Acknowledge Status Time Interrupt Flag
- WRIF: Data Write Interrupt Flag
- ADRIF: Address Interrupt Flag
- PCIF: Stop Condition Interrupt Flag
- RSCIF: Restart Condition Interrupt Flag
- SCIF: Start Condition Interrupt Flag
When any of the flag bits in I2CxPIR become set and the associated interrupt enable bits in I2CxPIE are set, the generic I2CxIF is also set. If the generic I2CxIE bit is set, an interrupt event is generated whenever one of the I2CxPIR flag bits becomes set. If the I2CxIE bit is clear, the I2CxPIR flag bit will still be set by hardware; however, no interrupt event will be triggered.
CNTIF becomes set (CNTIF = 1
) when the I2CxCNT register value reaches zero, indicating that all data bytes in the
I2C packet have been transmitted or received. CNTIF is set after the 9th
falling SCL edge when I2CxCNT reaches zero (I2CxCNT = 0
).
ACKTIF is set (ACKTIF = 1
) by the 9th falling edge of SCL for any byte
when the device is addressed as a client in any Client or Multi-Host mode. If the
Acknowledge Interrupt and Hold Enable (ACKTIE) bit is set and ACKTIF becomes set:
- If an ACK is
detected, clock stretching is also enabled (CSTR =
1
). - If a NACK is detected, no clock
stretching occurs (CSTR =
0
).
1
) after the 8th falling edge of SCL when the module
receives a data byte in Client or Multi-Host modes. Once the data byte is received, WRIF
is set, as is the Receive Buffer Full Status (RXBF) bit, the I2CxRXIF bit, and if the Data Write Interrupt and Hold Enable
(WRIE) bit is set, the generic I2CxIF bit is also set. WRIF is a
read/write bit and must be cleared in software, while the RXBF, I2CxRXIF, and I2CxIF bits are read-only and are cleared by reading
I2CxRXB
or by setting the Clear Buffer bit (CLRBF = 1
).PCIF is set whenever a Stop condition is detected on the bus.
RSCIF is set upon the detection of a Restart condition.
SCIF is set upon the detection of a Start condition.
In addition to the I2CxPIR register, the I2C Error (I2CxERR) register contains three interrupt flag bits that are used to detect bus errors. These read/write bits are set by module hardware but must be cleared by user software. The I2CxERR register also includes the interrupt enable bits for these three error conditions, and when set, will cause an interrupt event whenever the associated interrupt flag bit becomes set.
I2CxERR contains the following interrupt flag bits:
- BTOIF: Bus Time-out Interrupt Flag
- BCLIF: Bus Collision Interrupt Flag
- NACKIF: NACK Detect Interrupt Flag
BTOIF is set when a bus time-out occurs. The bus time-out period is configured using one of the time-out sources selected by the I2C Bus Time-out (I2CxBTO) register.
1
), BTOIF is set, the SMA and CSTR bits are cleared, and if the Bus Time-out Interrupt Enable (BTOIE) bit is set, the generic I2C Error Interrupt Flag (I2CxEIF)
bit is set, and the module is reset. If a bus time-out event occurs and the module is configured as a host and is active
(MMA = 1
), BTOIF is set, and if BTOIE is set,
I2CxEIF is set, and the module attempts to issue a Stop condition. The Stop condition is
generated only after the module detects an Idle condition, and the MMA bit is only
cleared by hardware after the detection of a Stop condition.
BCLIF is set upon the detection of a bus collision. A bus collision occurs any time the SDA line is sampled at a logic low while the module expects both SCL and SDA lines to be at a high logic level. When a bus collision occurs, BCLIF is set, and if the Bus Collision Detect Interrupt Enable (BCLIE) bit is set, I2CxEIF is also set, and the module is reset.
NACKIF is set when either the host or client is active (SMA =
1
|| MMA =
1
) and a NACK response is detected on the bus. A NACK response
occurs during the 9th SCL pulse in which the SDA line is released to a logic high. In
Host mode, a NACK can be issued when the host has finished receiving data from a client
or when the host receives incorrect data. In Client mode, a NACK is issued when the
client does not receive a matching address or when it receives incorrect data. A NACK
can also be automatically issued when any of the following bits become set, which will
also set NACKIF and I2CxEIF:
- TXWE: Transmit Write Error Status
- RXRE: Receive Read Error Status
- TXU: Transmit Underflow Status
- RXO: Receive Overflow Status