Spi slave operation example – Rainbow Electronics ATmega3290P_V User Manual
Page 191

191
ATmega329/3290/649/6490
2552H–AVR–11/06
The following code demonstrates how to use the USI module as a SPI Master with max-
imum speed (fsck = fck/4):
SPITransfer_Fast:
sts USIDR,r16
ldi r16,(1< ldi r17,(1< sts USICR,r16 ; MSB sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 sts USICR,r17 sts USICR,r16 ; LSB sts USICR,r17 lds r16,USIDR ret SPI Slave Operation Example The following code demonstrates how to use the USI module as a SPI Slave: init: ldi r16,(1< sts USICR,r16 ... SlaveSPITransfer: sts USIDR,r16 ldi r16,(1< sts USISR,r16 SlaveSPITransfer_loop: lds r16, USISR sbrs r16, USIOIF rjmp SlaveSPITransfer_loop lds r16,USIDR ret 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-