Rainbow-electronics ATmega8515L Manuel d'utilisateur Page 126

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 223
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 125
126
ATmega8515(L)
2512A–AVR–04/02
The following codeexamplesshowhow to initializethe SPI as a Slave andhow to per-
formasimple reception.
Note: 1. Theexample codeassumes that the part specificheaderfileis included.
Assembly Code Example
(1)
SPI_SlaveInit:
; Set MISO output, all others input
ldi r17,(1<<DD_MISO)
out DDR_SPI,r17
; Enable SPI
ldi r17,(1<<SPE)
out SPCR,r17
ret
SPI_SlaveReceive:
; Wait for reception complete
sbis SPSR,SPIF
rjmp SPI_SlaveReceive
; Read received data and return
in r16,SPDR
ret
CCode Example
(1)
void SPI_SlaveInit(void)
{
/* Set MISO output, all others input */
DDR_SPI = (1<<DD_MISO);
/* Enable SPI */
SPCR = (1<<SPE);
}
char SPI_SlaveReceive(void)
{
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)))
;
/* Return data register */
return SPDR;
}
Vue de la page 125
1 2 ... 121 122 123 124 125 126 127 128 129 130 131 ... 222 223

Commentaires sur ces manuels

Pas de commentaire