Datasheet

Figure 26-13. Data Transfer in Master Receiver Mode
Device 1
MASTER
RECEIVER
Device 2
SLAVE
TRANSMITTER
Device 3
Device n
SDA
SCL
........
R1 R2
V
CC
A START condition is sent by writing to the TWI Control Register (TWCRn) a value of the type
TWCRn=1x10x10x:
TWCRn.TWEN must be written to '1' to enable the two-wire serial interface
TWCRn.TWSTA must be written to '1' to transmit a START condition
TWCRn.TWINT must be cleared by writing a '1' to it
The TWI 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 the Status Code table below). In order to enter MR mode, SLA
+R must be transmitted. This is done by writing SLA+R to TWDR. Thereafter, the TWINT flag should be
cleared (by writing '1' to it) to continue the transfer. This is accomplished by writing a value to TWCRn of
the type TWCRn=1x00x10x.
When SLA+R has been transmitted and an acknowledgment bit has been received, TWINT is set again
and a number of status codes in TWSRn are possible. Possible status codes in Master mode are 0x38,
0x40, or 0x48. The appropriate action to be taken for each of these status codes is detailed in the table
below. Received data can be read from the TWDR register when the TWINT flag is set high by hardware.
This scheme is repeated until the last byte has been received. After the last byte has been received, the
MR should inform the ST by sending a NACK after the last received data byte. The transfer is ended by
generating a STOP condition or a repeated START condition. A repeated START condition is sent by
writing to the TWI Control Register (TWCRn) a value of the type TWCRn=1x10x10x again. A STOP
condition is generated by writing TWCRn=1x01x10x:
After a repeated START condition (status code 0x10) the two-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 losing control
over the bus.
Table 26-4. Status codes for Master Receiver Mode
Status Code
(TWSRn)
Prescaler Bits
are 0
Status of the Two-Wire Serial
Bus and Two-Wire Serial
Interface Hardware
Application Software Response Next Action Taken by TWI
Hardware
To/From
TWD
To TWCRn
STA STO TWINT TWEA
0x08 A START condition has been
transmitted
Load SLA+R 0 0 1 X SLA+R will be transmitted
ATmega48PA/88PA/168PA
Two-Wire Serial Interface (TWI)
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 288