ATMEGA325-16AJ ATMEL [ATMEL Corporation], ATMEGA325-16AJ Datasheet - Page 181

no-image

ATMEGA325-16AJ

Manufacturer Part Number
ATMEGA325-16AJ
Description
8-bit Microcontroller with In-System Programmable Flash
Manufacturer
ATMEL [ATMEL Corporation]
Datasheet
SPI Slave Operation Example
2570A–AVR–09/04
The following code demonstrates how to use the USI module as a SPI Master with max-
imum speed (fsck = fck/4):
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 is called is trans-
SPITransfer_Fast:
ret
init:
...
SlaveSPITransfer:
SlaveSPITransfer_loop:
sts
ldi
ldi
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
sts
lds
ldi
sts
sts
ldi
sts
lds
sbrs
rjmp
lds
ret
USIDR,r16
r16,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)
r17,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)
USICR,r16 ; MSB
USICR,r17
USICR,r16
USICR,r17
USICR,r16
USICR,r17
USICR,r16
USICR,r17
USICR,r16
USICR,r17
USICR,r16
USICR,r17
USICR,r16
USICR,r17
USICR,r16 ; LSB
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
ATmega325/3250/645/6450
181

Related parts for ATMEGA325-16AJ