27.7.2 Master Receiver Mode

In the Master Receiver (MR) mode, a number of data bytes are received from a Slave Transmitter (see next figure). In order to enter a Master mode, a START condition must be transmitted. The format of the following address packet determines whether Master Transmitter (MT) or MR mode is to be entered. If SLA+W is transmitted, MT mode is entered, if SLA+R is transmitted, MR mode is entered. All the status codes mentioned in this section assume that the prescaler bits are zero or are masked to zero.

Figure 27-13. Data Transfer in Master Receiver Mode
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 2-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 2-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 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 the a value to TWCRn of the type TWCRn=1x00x10x.

When SLA+R have 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 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 losing control over the bus.

Table 27-4. Status codes for Master Receiver Mode
Status Code

(TWSRn)

Prescaler Bits are 0

Status of the 2-wire Serial Bus and 2-wire Serial Interface HardwareApplication Software ResponseNext Action Taken by TWI Hardware
To/from TWDTo TWCRn
STASTOTWINTTWEA
0x08A START condition has been transmittedLoad SLA+R001XSLA+R will be transmitted

ACK or NOT ACK will be received

0x10A repeated START condition has been transmittedLoad SLA+R 001XSLA+R will be transmitted

ACK or NOT ACK will be received

Load SLA+W001X

SLA+W will be transmitted

Logic will switch to Master Transmitter mode

0x38Arbitration lost in SLA+R or NOT ACK bitNo TWDR action 001X2-wire Serial Bus will be released and not addressed Slave mode will be entered
101X

A START condition will be transmitted when the bus becomes free

0x40SLA+R has been transmitted;

ACK has been received

No TWDR action 0010Data byte will be received and NOT ACK will be returned
0011Data byte will be received and ACK will be returned
0x48SLA+R has been transmitted;

NOT ACK has been received

101XRepeated START will be transmitted
011X

STOP condition will be transmitted and TWSTO Flag will be reset

111XSTOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset
0x50Data byte has been received;

ACK has been returned

Read data byte 0010Data byte will be received and NOT ACK will be returned
0011Data byte will be received and ACK will be returned
0x58Data byte has been received;

NOT ACK has been returned

Read data byte 101XRepeated START will be transmitted
011X

STOP condition will be transmitted and TWSTO Flag will be reset

111XSTOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset
Figure 27-14. Formats and States in the Master Receiver Mode