AT32UC3C2512C Automotive Atmel Corporation, AT32UC3C2512C Automotive Datasheet - Page 126

no-image

AT32UC3C2512C Automotive

Manufacturer Part Number
AT32UC3C2512C Automotive
Description
Manufacturer
Atmel Corporation
16.3.3
126
Atmel ATtiny24/44/84 [Preliminary]
SPI Slave Operation Example
The following code demonstrates how to use the USI module as a SPI Slave:
The code is size optimized using only eight instructions (+ ret). The code example assumes
that the DO is configured as output and USCK pin is configured as input in the DDR register.
The value stored in register r16 prior to the function being called is transferred to the master
device, and when the transfer is completed, the data received from the master is stored back
into the r16 register.
Note that the first two instructions are for initialization only and need only to be executed once.
These instructions set the three-wire mode and positive edge shift register clock. The loop is
repeated until the USI counter overflow flag is set.
ret
init:
...
SlaveSPITransfer:
SlaveSPITransfer_loop:
out
in
ldi
out
out
ldi
out
in
sbrs
rjmp
in
ret
USICR,r17
r16,USIDR
r16,(1<<USIWM0)|(1<<USICS1)
USICR,r16
USIDR,r16
r16,(1<<USIOIF)
USISR,r16
r16, USISR
r16, USIOIF
SlaveSPITransfer_loop
r16,USIDR
7701E–AVR–02/11

Related parts for AT32UC3C2512C Automotive