26.5.11 Slave Status

Normal TWI operation dictates that the Slave Status register should be regarded purely as a read-only register. Clearing any of the status flags will indirectly be done when accessing the Slave Data (TWIn.SDATA) register or the CMD bits in the Slave Control B register (TWIn.SCTRLB).

Name: SSTATUS
Offset: 0x0B
Reset: 0x00
Property: -

Bit 76543210 
 DIFAPIFCLKHOLDRXACKCOLLBUSERRDIRAP 
Access R/WR/WRRR/WR/WRR 
Reset 00000000 

Bit 7 – DIF Data Interrupt Flag

This flag is set when a slave byte transmit or byte receive operation is successfully completed without any bus error. The flag can be set with an unsuccessful transaction in case of collision detection (see the description of the COLL Status bit). Writing a ‘1’ to its bit location will clear the DIF. However, normal use of the TWI does not require the DIF flag to be cleared by using this method, since the flag is automatically cleared when:

  1. Writing to the Slave DATA register.
  2. Reading the Slave DATA register.
  3. Writing a valid command to the CTRLB register.

The DIF flag can be used to generate a slave data interrupt (see the description of the DIEN control bit in TWIn.CTRLA).

Bit 6 – APIF Address or Stop Interrupt Flag

This flag is set when the slave address match logic detects that a valid address has been received or by a Stop condition. Writing a ‘1’ to its bit location will clear the APIF. However, normal use of the TWI does not require the flag to be cleared by this method since the flag is cleared using the same software interactions as described for the DIF flag.

The APIF flag can be used to generate a slave address or stop interrupt (see the description of the AIEN control bit in TWIn.CTRLA). Take special note of that the slave stop interrupt shares the interrupt vector with the slave address interrupt.

Bit 5 – CLKHOLD Clock Hold

If read as ‘1’, the slave clock hold flag indicates that the slave is currently holding the TWI clock (SCL) low, stretching the TWI clock period. This is a read-only bit that is set when an address or data interrupt is set. Resetting the corresponding interrupt will indirectly reset this flag.

Bit 4 – RXACK Received Acknowledge

This bit is read-only and contains the most recently received Acknowledge bit from the master. When read as ‘0’, the most recent acknowledge bit from the master was ACK. When read as ‘1’, the most recent acknowledge bit was NACK.

Bit 3 – COLL Collision

If read as ‘1’, the transmit collision flag indicates that the slave has not been able to transmit a high data or NACK bit. If a slave transmit collision is detected, the slave will commence its operation as normal, except no low values will be shifted out onto the SDA line (i.e., when the COLL flag is set to ‘1’ it disables the data and acknowledge output from the slave logic). The DIF flag will be set to ‘1’ at the end as a result of the internal completion of an unsuccessful transaction. Similarly, when a collision occurs because the slave has not been able to transmit NACK bit, it means the address match already happened and APIF flag is set as a result. APIF/DIF flags can only generate interrupts whose handlers can be used to check for the collision. Writing a ‘1’ to its bit location will clear the COLL flag. However, the flag is automatically cleared if any Start condition (S/Sr) is detected.

This flag is intended for systems where the address resolution protocol (ARP) is employed. However, a detected collision in non-ARP situations indicates that there has been a protocol violation and should be treated as a bus error.

Bit 2 – BUSERR Bus Error

The BUSERR flag indicates that an illegal bus condition has occurred. An illegal bus condition is detected if a protocol violating Start (S), Repeated Start (Sr), or Stop (P) is detected on the TWI bus lines. A Start condition directly followed by a Stop condition is one example of protocol violation. Writing a ‘1’ to its bit location will clear the BUSERR flag. However, normal use of the TWI does not require the BUSERR to be cleared by this method. A robust TWI driver software design will assume that the entire packet of data has been corrupted and restart by waiting for a new Start condition (S). The TWI bus error detector is part of the TWI Master circuitry. For bus errors to be detected, the TWI Master must be enabled (ENABLE bit in TWIn.MCTRLA is ‘1’), and the system clock frequency must be at least four times the SCL frequency.

Bit 1 – DIR Read/Write Direction

This bit is read-only and indicates the current bus direction state. The DIR bit reflects the direction bit value from the last address packet received from a master TWI device. If this bit is read as ‘1’, a master read operation is in progress. Consequently, a ‘0’ indicates that a master write operation is in progress.

Bit 0 – AP Address or Stop

When the TWI slave address or Stop Interrupt Flag (APIF) is set, this bit determines whether the interrupt is due to address detection or a Stop condition.

ValueNameDescription
0 STOP A Stop condition generated the interrupt on APIF
1 ADR Address detection generated the interrupt on APIF