Datasheet

115
ATmega323(L)
1457E11/01
Figure 57. Formats and States in the Slave Receiver Mode
Assembly Code Example
Slave Receiver Mode
;Part specific include file and TWI include file must be included.
; <Initialize registers TWAR and TWBR>
ldi r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
out TWCR, r16 ; Enable TWI in Slave Receiver Mode
; <Receive START condition and SLA+W>
wait10:in r16,TWCR ; Wait for TWINT flag set. This indicates that
sbrs r16, TWINT ; START followed by SLA+W has been received
rjmp wait10
in r16, TWSR ; Check value of TWI Status Register. If status
cpi r16, SR_SLA_ACK ; different from SR_SLA_ACK, go to ERROR
brne ERROR
ldi r16, (1<<TWINT) | (1<<TWEA) | (1<<TWEN)
out TWCR, r16 ; Clear TWINT bit in TWCR to start reception of
; first data byte. Setting TWEA indicates that
S SLA W A DATA A
$60 $80
$88
A
$68
Reception of the own
slave address and one or
more data bytes. All are
acknowledged
Last data byte received
is not acknowledged
Arbitration lost as master
and addressed as slave
Reception of the general call
address and one or more data
bytes
Last data byte received is
not acknowledged
n
From master to slave
From slave to master
Any number of data bytes
and their associated acknowledge bits
This number (contained in TWSR) corresponds
to a defined state of the 2-Wire Serial Bus
P or SDATA A
$80
$A0
P or SA
A DATA A
$70 $90
$98
A
$78
P or SDATA A
$90
$A0
P or SA
General Call
Arbitration lost as master and
addressed as slave by general call
DATA A