EasyManuals Logo

Atmel AVR AT90CAN32 User Manual

Atmel AVR AT90CAN32
428 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
7679H–CAN–08/08
AT90CAN32/64/128
The following code examples show how to initialize the SPI as a Slave and how to perform a
simple reception.
Note: 1. The example code assumes that the part specific header file is included.
16.2 SS Pin Functionality
16.2.1 Slave Mode
When the SPI is configured as a Slave, the Slave Select (SS)
pin is always input. When SS is
held low, the SPI is activated, and MISO becomes an output if configured so by the user. All
other pins are inputs. When SS
is driven high, all pins are inputs, and the SPI is passive, which
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;
}

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Atmel AVR AT90CAN32 Specifications

General IconGeneral
BrandAtmel
ModelAVR AT90CAN32
CategoryMicrocontrollers
LanguageEnglish

Related product manuals