Atmel ATmega32M1 Manual page 162

8-bit avr microcontroller with16k/32k/64k bytes in-system programmable flash
Table of Contents

Advertisement

Atmel ATmega16/32/64/M1/C1
162
Assembly Code Example
SPI_SlaveInit:
; Set MISO output, all others input
r17,(1<<DD_MISO)
ldi
out
DDR_SPI,r17
; Enable SPI
r17,(1<<SPE)
ldi
SPCR,r17
out
ret
SPI_SlaveReceive:
; Wait for reception complete
sbis SPSR,SPIF
rjmp SPI_SlaveReceive
; Read received data and return
r16,SPDR
in
ret
(1)
C Code Example
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;
}
Note:
1. The example code assumes that the part specific header file is included.
(1)
7647H–AVR–03/12

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

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

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Atmega64c1Atmega16m1Atmega32c1Atmega64m1

Table of Contents