25.6.3 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 25-13. Data Transfer in Master Receiver Mode
A START condition is sent by writing to the TWI Control register (TWCR) a value of the type TWCR=1x10x10x:
  • TWCR.TWEN must be written to '1' to enable the 2-wire Serial Interface
  • TWCR.TWSTA must be written to '1' to transmit a START condition
  • TWCR.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 TWSR 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 TWCR of the type TWCE=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 TWSR 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 (TWCR) a value of the type TWCR=1x10x10x again. A STOP condition is generated by writing TWCR=1xx01x10x:

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 25-4. Status codes for Master Receiver Mode
Status Code

(TWSR)

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 TWCR
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 or

Load SLA+W

0

0

0

0

1

1

X

X

SLA+R will be transmitted

ACK or NOT ACK will be received

SLA+W will be transmitted

Logic will switch to Master Transmitter mode

0x38Arbitration lost in SLA+R or NOT ACK bitNo TWDR action or

No TWDR action

0

1

0

0

1

1

X

X

2-wire Serial Bus will be released and not addressed Slave mode will be entered

A START condition will be transmitted when the bus

becomes free

0x40SLA+R has been transmitted;

ACK has been received

No TWDR action or

No TWDR action

0

0

0

0

1

1

0

1

Data byte will be received and NOT ACK will be

returned

Data byte will be received and ACK will be returned

0x48SLA+R has been transmitted;

NOT ACK has been received

No TWDR action or

No TWDR action or

No TWDR action

1

0

1

0

1

1

1

1

1

X

X

X

Repeated START will be transmitted

STOP condition will be transmitted and TWSTO Flag will be reset

STOP 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 or

Read data byte

0

0

0

0

1

1

0

1

Data byte will be received and NOT ACK will be

returned

Data byte will be received and ACK will be returned

0x58Data byte has been received;

NOT ACK has been returned

Read data byte or

Read data byte or

Read data byte

1

0

1

0

1

1

1

1

1

X

X

X

Repeated START will be transmitted

STOP condition will be transmitted and TWSTO Flag will be reset

STOP condition followed by a START condition will be transmitted and TWSTO Flag will be reset

Figure 25-14. Formats and States in the Master Receiver Mode