Rainbow-electronics ATmega162V Manual de usuario Pagina 160

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 323
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 159
160
ATmega162/V
2513E–AVR–09/03
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;
}
Vista de pagina 159
1 2 ... 155 156 157 158 159 160 161 162 163 164 165 ... 322 323

Comentarios a estos manuales

Sin comentarios