Datasheet
Figure 23-1. SPI Block Diagram
SPI2X
SPI2X
DIVIDER
/2/4/8/16/32/64/128
Note: Refer to the pin-out description and the I/O Port description for SPI pin placement.
The interconnection between master and slave CPUs with SPI is shown in the figure below. The system
consists of two shift registers and a master clock generator. The SPI Master initiates the communication
cycle when pulling low the Slave Select SS pin of the desired slave. Master and slave prepare the data to
be sent in their respective shift registers, and the master generates the required clock pulses on the SCK
line to interchange data. Data is always shifted from master to slave on the Master Out – Slave In (MOSI)
line, and from slave to master on the Master In – Slave Out (MISO) line. After each data packet, the
master will synchronize the slave by pulling high the Slave Select, SS, line.
When configured as a master, the SPI interface has no automatic control of the SS line. This must be
handled by user software before communication can start. When this is done, writing a byte to the SPI
Data register starts the SPI clock generator, and the hardware shifts the eight bits into the slave. After
shifting one byte, the SPI clock generator stops, setting the end of Transmission Flag (SPIF). If the SPI
Interrupt Enable bit (SPIE) in the SPCR register is set, an interrupt is requested. The master may
continue to shift the next byte by writing it into SPDR, or signal the end of packet by pulling high the Slave
Select, SS line. The last incoming byte will be kept in the Buffer register for later use.
When configured as a slave, the SPI interface will remain sleeping with MISO tri-stated as long as the SS
pin is driven high. In this state, the software may update the contents of the SPDR, but the data will not
be shifted out by incoming clock pulses on the SCK pin until the SS pin is driven low. As one byte has
been completely shifted, the end of transmission flag, SPIF is set. If the SPIE in the SPCR register is set,
ATmega48PA/88PA/168PA
Serial Peripheral Interface (SPI)
© 2018 Microchip Technology Inc.
Datasheet Complete
DS40002011A-page 228