268
8331B–AVR–03/12
Atmel AVR XMEGA AU
shows an example where two TWI masters are contending for bus ownership. Both
devices are able to issue a START condition, but DEVICE1 loses arbitration when attempting to
transmit a high level (bit 5) while DEVICE2 is transmitting a low level.
Arbitration between a repeated START condition and a data bit, a STOP condition and a data
bit, or a repeated START condition and a STOP condition are not allowed and will require spe-
cial handling by software.
21.3.9
Synchronization
A clock synchronization algorithm is necessary for solving situations where more than one mas-
ter is trying to control the SCL line at the same time. The algorithm is based on the same
principles used for the clock stretching previously described.
shows an example
where two masters are competing for control over the bus clock. The SCL line is the wired-AND
result of the two masters clock outputs.
Figure 21-10.
Clock synchronization.
A high-to-low transition on the SCL line will force the line low for all masters on the bus, and they
will start timing their low clock period. The timing length of the low clock period can vary among
the masters. When a master (DEVICE1 in this case) has completed its low period, it releases the
SCL line. However, the SCL line will not go high until all masters have released it. Consequently,
the SCL line will be held low by the device with the longest low period (DEVICE2). Devices with
shorter low periods must insert a wait state until the clock is released. All masters start their high
period when the SCL line is released by all devices and has gone high. The device which first
completes its high period (DEVICE1) forces the clock line low, and the procedure is then
repeated. The result is that the device with the shortest clock period determines the high period,
while the low period of the clock is determined by the device with the longest clock period.
21.4
TWI Bus State Logic
The bus state logic continuously monitors the activity on the TWI bus lines when the master is
enabled. It continues to operate in all sleep modes, including power-down.
The bus state logic includes START and STOP condition detectors, collision detection, inactive
bus timeout detection, and a bit counter. Theseare used to determine the bus state. Software
can get the current bus state by reading the bus state bits in the master status register. The bus
state can be unknown, idle, busy, or owner, and is determined according to the state diagram
shown in
. The values of the bus state bits according to state are shown in binary in
the figure.
DEVICE1_SCL
SCL
(wired-AND)
Wait
State
DEVICE2_SCL
High Period
Count
Low Period
Count