25.3.2.2.4 Transmitting Data Packets

Assuming the above M1 case, the TWI host can start transmitting data by writing to the Host Data (TWIn.MDATA) register, which will also clear the Write Interrupt Flag (WIF). During the data transfer, the host is continuously monitoring the bus for collisions and errors. The WIF flag will be set to ‘1’ after the data packet transfer has been completed.

If the transmission is successful and the host receives an ACK bit from the client, the Received Acknowledge (RXACK) flag will be set to ‘0’, meaning that the client is ready to receive new data packets.

The software can prepare to take one of the following actions:
  • Transmit a new data packet
  • Transmit a new address packet
  • Complete the transaction by issuing a Stop condition in the Command (MCMD) bit field from the Host Control B (TWIn.MCTRLB) register

If the transmission is successful and the host receives a NACK bit from the client, the RXACK flag will be set to ‘1’, meaning that the client is not able to or does not need to receive more data.

The software can prepare to take one of the following actions:
  • Transmit a new address packet
  • Complete the transaction by issuing a Stop condition in the Command (MCMD) bit field from the Host Control B (TWIn.MCTRLB) register

The RXACK status is valid only if the WIF flag is set to ‘1’ and the Arbitration Lost (ARBLOST) and Bus Error (BUSERR) flags are set to ‘0’.

The transmission can be unsuccessful if a collision is detected. Then, the host will lose the arbitration, the Arbitration Lost (ARBLOST) flag will be set to ‘1’, and the bus state changes to Busy. An arbitration lost during the sending of the data packet is treated the same way as the above M4 case.

The WIF, ARBLOST, BUSERR and RXACK flags are all located in the Host Status (TWIn.MSTATUS) register.