Assembly code example - master receiver mode, Figure 53), Atmega163(l) – Rainbow Electronics ATmega163L User Manual
Page 79
![background image](/manuals/281753/79/background.png)
ATmega163(L)
79
Figure 53. Formats and States in the Master Receiver Mode
Assembly Code Example - Master Receiver Mode
;Part specific include file and TWI include file must be included.
;
ldi
r16, (1< out TWCR, r16 ;Send START condition wait5: in r16,TWCR ; Wait for TWINT flag set. This indicates that sbrs r16, TWINT ; the START condition has been transmitted rjmp wait5 in r16, TWSR ; Check value of TWI Status Register. If status cpi r16, START ; different from START, go to ERROR brne ERROR ldi r16, 0xc9 ; Load SLA+R into TWDR register out TWDR, r16 ldi r16, (1< out TWCR, r16 ; Clear TWINT bit in TWCR to start transmission of SLA+R S SLA R A DATA A $08 $40 $50 S SLA R $10 A P $48 A or A $38 Other master continues $38 Other master continues W A $68 Other master continues $78 $B0 To corresponding MR MT Successfull Next transfer Not acknowledge Arbitration lost in slave Arbitration lost and DATA A n From master to slave From slave to master Any number of data bytes This number (contained in TWSR) corresponds P DATA A $58 A
states in slave mode
reception
from a slave
receiver
started with a
repeated start
condition
received after the
slave address
address or data byte
addressed as slave
and their associated acknowledge bits
to a defined state of the 2-Wire Serial Bus