Rainbow-electronics ATmega8515L Uživatelský manuál Strana 126

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 223
  • Tabulka s obsahem
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 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;
}
Zobrazit stránku 125
1 2 ... 121 122 123 124 125 126 127 128 129 130 131 ... 222 223

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

Žádné komentáře