EasyManuals Logo

Atmel ATmega328 User Manual

Atmel ATmega328
567 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #172 background imageLoading...
Page #172 background image
172
8271D–AVR–05/11
ATmega48A/PA/88A/PA/168A/PA/328/P
The following code examples show how to initialize the SPI as a Slave and how to perform a
simple reception.
Note: 1. See ”About Code Examples” on page 8.
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
in r16, SPSR
sbrs r16, 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;
}

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Atmel ATmega328 and is the answer not in the manual?

Atmel ATmega328 Specifications

General IconGeneral
BrandAtmel
ModelATmega328
CategoryMicrocontrollers
LanguageEnglish

Related product manuals