Rainbow-electronics ATmega3290P_V Uživatelský manuál Strana 191

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 375
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 190
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<<USIWM0)|(0<<USICS0)|(1<<USITC)
ldi r17,(1<<USIWM0)|(0<<USICS0)|(1<<USITC)|(1<<USICLK)
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<<USIWM0)|(1<<USICS1)
sts USICR,r16
...
SlaveSPITransfer:
sts USIDR,r16
ldi r16,(1<<USIOIF)
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-
Zobrazit stránku 190
1 2 ... 186 187 188 189 190 191 192 193 194 195 196 ... 374 375

Komentáře k této Příručce

Žádné komentáře