Rainbow-electronics ATtiny26L Manuel d'utilisateur Page 70

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 151
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 69
70
ATtiny26(L)
1477BAVR04/02
The following code demonstrates how to use the USI module as a SPI Master with max-
imum speed (fsck = fck/2):
SPITransfer_Fast:
out USIDR,r16
ldi r16,(1<<USIWM0)+(0<<USICS0)+(1<<USITC)
ldi r17,(1<<USIWM0)+(0<<USICS0)+(1<<USITC)+(1<<USICLK)
out USICR,r16 ; MSB
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16
out USICR,r17
out USICR,r16 ; LSB
out USICR,r17
in 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)
out USICR,r16
...
SlaveSPITransfer:
out USIDR,r16
ldi r16,(1<<USIOIF)
out USISR,r16
SlaveSPITransfer_loop:
sbis USISR,USIOIF
rjmp SlaveSPITransfer_loop
in r16,USIDR
ret
The code is size optimized using only 8 instructions (+ ret). The code example assumes
that the DO is configured as output and SCK pin is configured as input in the DDRB
Register. The value stored in register r16 prior to the function is called is transferred to
the master device, and when the transfer is completed the data received from the mas-
ter is stored back into the r16 register.
Vue de la page 69
1 2 ... 65 66 67 68 69 70 71 72 73 74 75 ... 150 151

Commentaires sur ces manuels

Pas de commentaire