3 Interrupts for Address Match, Transmit Buffer Empty, Receive Buffer Full, Bus Time-Out, Data Byte Count, Acknowledge, and Not Acknowledge

The stand-alone I2C module contains additional interrupt features designed to assist with communication functions. In addition to the MSSP module’s Start/Restart Condition (SCIF), Stop Condition (PCIF), Bus Collision (BCLIF), and transmit, receive, and acknowledge (SSPIF) interrupts, the stand-alone I2C module adds an Address Match (ADRIF), Transmit Buffer Empty (TXBE), Receive Buffer Full (RXBF), Bus Time-Out (BTOIF), Data Byte Count (CNTIF), Acknowledge Status Time (ACKTIF), and Not Acknowledge Detect (NACKIF).

The stand-alone I2C module incorporates a new register, the I2C Interrupt Flag register (I2CxPIR), which handles several I2C related interrupts. Additionally, when any of the flag bits in I2CxPIR become set and the associated I2CxPIE Interrupt Enable bit is set, the generic I2C Interrupt Flag (I2CxIF) is also set. If the matching Interrupt Enable bit is set, an interrupt is generated whenever the Interrupt Flag bit is set. If the associated Interrupt Enable bit is clear, the Interrupt flag will still be set when the Interrupt condition occurs, however, no interrupt will be triggered.

Important: Note that the generic I2CxIF bit is read-only and is only cleared by hardware when all bits in the I2CxPIR register are clear.

The 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

The CNTIF becomes set (CNTIF = 1) when the I2CxCNT register value reaches ‘0’, indicating that all bytes in the data frame have been transmitted or received. CNTIF is set after the 9th falling edge of SCL when the I2CxCNT = 0.

The ACKTIF becomes set (ACKTIF = 1) after the 9th falling edge of SCL for any byte when the device is addressed as a slave in any I2C Slave mode or I2C Multi-Master mode whenever an ACK is detected.

The WRIF becomes set (WRIF = 1) after the 8th falling edge of SCL when the module receives a data byte. This bit is only active in any I2C Slave mode or I2C Multi-Master mode. Once the data byte is received, WRIF is set, as is the Receive Buffer Full Status (RXBF) bit, the I2C Receive Interrupt Flag (I2CxRXIF) bit, and if the Data Write Interrupt and Hold Enable (WRIE) bit is set, the generic I2CxIF bit is also set. The WRIF bit is read/write and must be cleared by user software, while the RXBF, I2CxRXIF, and I2CxIF are read-only, and are cleared by reading the I2CxRXB.

The ADRIF becomes set on the 8th falling edge of SCL after the module has received either a matching 7-bit address byte or the matching upper or lower bytes of a 10-bit address. This bit is only active in Slave mode or Multi-Master mode. Upon receiving a matching address byte, the ADRIF bit is set.

The PCIF is set whenever a Stop condition is detected on the bus.

The RSCIF is set upon the detection of a Restart condition.

The SCIF is set upon the detection of a Start condition.

In addition to the I2CxPIR register, the stand-alone module incorporates the I2C Error (I2CxERR) register. The I2CxERR register contains three Interrupt Flag bits that are used to detect bus errors. These bits are read/write and must be cleared by user software. The I2CxERR register also includes the Enable bits for these three functions.

The I2CxERR register contains the following Interrupt Flag bits:

  • BTOIF: Bus Time-Out Interrupt Flag
  • BCLIF: Bus Collision Detect Interrupt Flag
  • NACKIF: NACK Detect Interrupt Flag

BTOIF is set when a bus time-out occurs. The bus time-out time frame is controlled by the I2C Bus Time-Out (I2CxBTO) register. If a bus time-out event occurs and the module is configured as a master and is active (MMA = 1), the BTOIF is set and the module immediately tries to issue a Stop condition. When BTOIF becomes set, and the associated Bus Time-Out Interrupt Enable (BTOIE) bit is set, the generic I2C Error Interrupt Flag (I2CxEIF) bit is also set. The I2CxEIF bit is read-only, and is cleared by hardware when all error Interrupt Flag bits in the I2CxERR register are clear.

BCLIF is set whenever a bus collision is detected. A bus collision occurs any time the SDA input is sampled low while the both the SDA and SCL outputs are high. When BCLIF is set, and the associated Bus Collision Detect Interrupt Enable (BCLIE) bit is set, the generic I2CxEIF bit is also set.

NACKIF is set when either the master or slave is active (SMA = 1 || MMA = 1) and a NACK is detected on the bus. A NACK response occurs during the 9th SCL pulse when the SDA line is released high. When the module is in Master mode, a NACK can be issued when the master has finished receiving data from the slave, or in the event it did not receive a byte. In Slave mode, the slave issues a NACK when it does not receive a matching address, or did not receive the last data byte. A NACK can also be automatically sent if any of the following bits are set, which will set NACKIF, and if the NACK Detect Interrupt Enable (NACKIE) bit is set, hardware also sets I2CxEIF:

  • TXWE: Transmit Write Error Status bit
  • RXRE: Receive Read Error Status bit
  • TXU: Transmit Underflow Status bit
  • RXO: Receive Overflow Status bit