271
8331B–AVR–03/12
Atmel AVR XMEGA AU
21.5.1.2
Case M2: Address packet transmit complete - Address not acknowledged by slave
If no slave device responds to the address, the master write interrupt flag and the master
received acknowledge flag are set. The clock hold is active at this point, preventing further activ-
ity on the bus.
21.5.1.3
Case M3: Address packet transmit complete - Direction bit cleared
If the master receives an ACK from the slave, the master write interrupt flag is set and the mas-
ter received acknowledge flag is cleared. The clock hold is active at this point, preventing further
activity on the bus.
21.5.1.4
Case M4: Address packet transmit complete - Direction bit set
If the master receives an ACK from the slave, the master proceeds to receive the next byte of
data from the slave. When the first data byte is received, the master read interrupt flag is set and
the master received acknowledge flag is cleared. The clock hold is active at this point, prevent-
ing further activity on the bus.
21.5.2
Transmitting Data Packets
Assuming case M3 above, the master can start transmitting data by writing to the master data
register. If the transfer was successful, the slave will signal with ACK. The master write interrupt
flag is set, the master received acknowledge flag is cleared, and the master can prepare new
data to send. During data transfer, the master is continuously monitoring the bus for collisions.
The received acknowledge flag must be checked by software for each data packet transmitted
before the next data packet can be transferred. The master is not allowed to continue transmit-
ting data if the slave signals a NACK.
If a collision is detected and the master loses arbitration during transfer, the arbitration lost flag is
set.
21.5.3
Receiving Data Packets
Assuming case M4 above, the master has already received one byte from the slave. The master
read interrupt flag is set, and the master must prepare to receive new data. The master must
respond to each byte with ACK or NACK. Indicating a NACK might not be successfully exe-
cuted, as arbitration can be lost during the transmission. If a collision is detected, the master
loses arbitration and the arbitration lost flag is set.
21.6
TWI Slave Operation
The TWI slave is byte-oriented with optional interrupts after each byte. There are separate slave
data and address/stop interrupts. Interrupt flags can also be used for polled operation. There are
dedicated status flags for indicating ACK/NACK received, clock hold, collision, bus error, and
read/write direction.
When an interrupt flag is set, the SCL line is forced low. This will give the slave time to respond
or handle data, and will in most cases require software interaction.
. shows the TWI
slave operation. The diamond shapes symbols (SW) indicate where software interaction is
required.