Datasheet

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
Circles are used to indicate that the TWINT flag is set. The numbers in the circles show the status code
held in TWSRn, with the prescaler bits masked to zero. At these points, actions must be taken by the
application to continue or complete the TWI transfer. The TWI transfer is suspended until the TWINT flag
is cleared by software.
When the TWINT flag is set, the status code in TWSRn 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 below in the status code table for each mode. Note that the prescaler bits are masked to zero in
these tables.
26.7.1 Master Transmitter Mode
In the Master Transmitter (MT) mode, a number of data bytes are transmitted to a slave receiver, see the
figure below. In order to enter a Master mode, a START condition must be transmitted. The format of the
following address packet determines whether MT or Master Receiver (MR) mode is to be entered: If SLA
+W is transmitted the MT mode is entered, if SLA+R is transmitted the MR mode is entered. All the status
codes mentioned in this section assume that the prescaler bits are zero or masked to zero.
Figure 26-11. Data Transfer in Master Transmitter Mode
Device 1
MASTER
TRANSMITTER
Device 2
SLAVE
RECEIVER
Device 3
Device n
SDA
SCL
........
R1 R2
V
CC
A START condition is sent by writing a value to the TWI Control Register n (TWCRn) of the type
TWCRn=1x10x10x:
The TWI Enable bit (TWCRn.TWEN) must be written to '1' to enable the two-wire serial interface
The TWI Start Condition bit (TWCRn.TWSTA) must be written to '1' to transmit a START condition
The TWI Interrupt Flag (TWCRn.TWINT) must be written to '1' to clear the flag.
The TWI n will then test the two-wire serial bus and generate a START condition as soon as the bus
becomes free. After a START condition has been transmitted, the TWINT flag is set by hardware, and the
status code in TWSRn will be 0x08 (see Status Code table below). In order to enter MT mode, SLA+W
ATmega48PA/88PA/168PA
Two-Wire Serial Interface (TWI)
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 283