EasyManua.ls Logo

Atmel ATmega48PV User Manual

Atmel ATmega48PV
452 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 #170 background imageLoading...
Page #170 background image
170
8025I–AVR–02/09
ATmega48P/88P/168P/328P
The following code examples show how to initialize the SPI as a Slave and how to perform a
simple reception.
Note: 1. See ”Code Examples” on page 7.
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

Question and Answer IconNeed help?

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

Atmel ATmega48PV Specifications

General IconGeneral
Architecture8-bit AVR
Operating Voltage1.8V - 5.5V
Flash Memory4 KB
SRAM512 Bytes
EEPROM256 Bytes
Clock Speed0 - 20 MHz
I/O Pins23
ADC Channels6
ADC Resolution10-bit
PWM Channels6
Operating Temperature-40°C to 85°C
Serial InterfacesUSART, SPI, I2C
Package OptionsMLF
Timers/CountersTwo 8-bit Timers/Counters, One 16-bit Timer/Counter

Related product manuals