ATAVRSB202 Atmel, ATAVRSB202 Datasheet - Page 102

no-image

ATAVRSB202

Manufacturer Part Number
ATAVRSB202
Description
KIT BATT MGMT FOR ATMEGA32HVB
Manufacturer
Atmel
Datasheets

Specifications of ATAVRSB202

Main Purpose
*
Embedded
*
Utilized Ic / Part
*
Primary Attributes
*
Secondary Attributes
*
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
8042B–AVR–06/10
The following code examples show how to initialize the SPI as a Slave and how to perform a
simple reception.
Note:
Assembly Code Example
C Code Example
void SPI_SlaveInit(void)
{
}
char SPI_SlaveReceive(void)
{
}
SPI_SlaveInit:
; Set MISO output, all others input
ldi
out
; Enable SPI
ldi
out
ret
SPI_SlaveReceive:
; Wait for reception complete
in r16,SPSR
sbrs r16,SPIF
rjmp SPI_SlaveReceive
; Read received data and return
in
ret
/* Set MISO output, all others input */
DDR_SPI = (1<<DD_MISO);
/* Enable SPI */
SPCR = (1<<SPE);
/* Wait for reception complete */
while(!(SPSR & (1<<SPIF)))
/* Return Data Register */
return SPDR;
1. See “About Code Examples” on page 8.
;
r17,(1<<DD_MISO)
DDR_SPI,r17
r17,(1<<SPE)
SPCR,r17
r16,SPDR
(1)
(1)
ATmega16HVB/32HVB
102

Related parts for ATAVRSB202