Datasheet

105
ATmega323(L)
1457E11/01
W: Write bit (low level at SDA)
A: Acknowledge bit (low level at SDA)
A
: Not acknowledge bit (high level at SDA)
Data: 8-bit data byte
P: STOP condition
SLA: Slave Address
In Figure 55 to Figure 58, circles are used to indicate that the 2-wire Serial Interface
interrupt flag is set. The numbers in the circles show the status code held in TWSR. At
these points, actions must be taken by the application to continue or complete the 2-wire
Serial Bus transfer. The 2-wire Serial Bus transfer is suspended until the 2-wire Serial
Interface interrupt flag is cleared by software.
The 2-wire Serial Interface interrupt flag is not automatically cleared by hardware when
executing the interrupt routine. Software has to clear the flag to continue the 2-wire
transfer. Also note that the 2-wire Serial Interface starts execution as soon as this bit is
cleared, so that all access to TWAR, TWDR, and TWSR must have been completed
before clearing this flag.
When the 2-wire Serial Interface interrupt flag is set, the status code in TWSR is used to
determine the appropriate software action. For each status code, the required software
action and details of the following serial transfer are given in Table 37 to Table 44.
Master Transmitter Mode In the master transmitter mode, a number of data bytes are transmitted to a slave
receiver (see Figure 55). Before master transmitter mode can be entered, the TWCR
must be initialized as follows:
TWEN must be set to enable the 2-wire Serial Interface, TWSTA and TWSTO must be
cleared.
The master transmitter mode may now be entered by setting the TWSTA bit. The 2-wire
Serial Interface logic will then test the 2-wire Serial Bus and generate a START condi-
tion as soon as the bus becomes free. When a START condition is transmitted, the 2-
wire Serial Interface interrupt flag (TWINT) is set by hardware, and the status code in
TWSR will be $08. TWDR must then be loaded with the slave address and the data
direction bit (SLA+W). Clearing the TWINT bit in software will continue the transfer. The
TWINT flag is cleared by writing a logic one to the flag.
When the slave address and the direction bit have been transmitted and an acknowl-
edgement bit has been received, TWINT is set again and a number of status codes in
TWSR are possible. Possible status codes in master mode are $18, $20, or $38. The
appropriate action to be taken for each of these status codes is detailed in Table 37. The
data must be loaded when TWINT is high only. If not, the access will be discarded, and
the Write Collision bit
TWWC will be set in the TWCR register. This scheme is
repeated until the last byte is sent and the transfer is ended by generating a STOP con-
dition or a repeated START condition. A STOP condition is generated by setting
TWSTO, a repeated START condition is generated by setting TWSTA and TWSTO.
After a repeated START condition (state $10) the 2-wire Serial Interface can access the
same slave again, or a new slave without transmitting a STOP condition. Repeated
START enables the master to switch between slaves, master transmitter mode and
master receiver mode without loosing control over the bus.
TWCR TWINT TWEA TWSTA TWSTO TWWC TWEN - TWIE
Value 0 X00010 X