Rainbow-electronics Atmega169L Manuale Utente Pagina 145

  • Scaricare
  • Aggiungi ai miei manuali
  • Stampa
  • Pagina
    / 317
  • Indice
  • SEGNALIBRI
  • Valutato. / 5. Basato su recensioni clienti
Vedere la pagina 144
145
ATmega169V/L
2514AAVR08/02
The following code examples show how to initialize the SPI as a Slave and how to per-
form a simple reception.
Note: 1. The example code assumes that the part specific header file is 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
C Code 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;
}
Vedere la pagina 144
1 2 ... 140 141 142 143 144 145 146 147 148 149 150 ... 316 317

Commenti su questo manuale

Nessun commento