SPI-Serial Peripheral Interface
SPI-Serial Peripheral Interface
Dhruv Satasiya
Content
• Introduction
• Why SPI Protocol?
• PIN Description
• How Does SPI Work?
• Types of SPI Communication
• SPI Protocol Configurations
• CPOL and CPHA
• SPI Transmission Process
• SPI Reception Process
Introduction
• SPI is a synchronous serial communication protocol used to communicate
with one master and one or more slave devices in Embedded Systems.
• Here, a Microcontroller can behave as a Master, while Slave devices may
include various sensors, EEPROM, Display, Bluetooth, etc.
• SPI protocol is famous for its simplicity and high data transfer speed.
• There are four fundamental pins on the master and slave sides.
Why SPI Protocol?
• SPI & I2C both protocols perform the best when it comes to speed as the
maximum rate of transferring the bits is fPLCK/2, which means if MCU is
running at 16MHz of frequency then SPI can transfer 8M bits per second.
• However the main drawback of SPI protocol is its capacity of distance. The
maximum distance for sending bits is only around 10 feet.
PIN Description
• MISO: Master In Slave Out, the
master receives data from the slave.
• MOSI: Master Out Slave In, the
master sends data to the slave.
• SLCK: Serial clock
• SS: Slave Select / Chip Select
• Connecting the MOSI pin of the master to the MOSI pin of the slave and the
MISO pin of the master to the MISO pin of the slave enables communication
between master and slave.
• One of the GPIO pins of the MCU can provide the serial clock to the slave.
• Pulling the NSS pin to the ground enables the corresponding slave device to
receive the data from the master.
• SPI communication is a simple technique based
Behind the Scene
on a shift register and two buffer registers.
• There are two buffer registers, one on the master
side and another on the slave side, usually known
as Tx and Rx buffers.
• As soon as the clock is enabled, at every clock
one bit is shifted from the master side to the
slave side and visa versa from the slave side to
the master side.
Fig. 2 SPI – Behind the Scene
• Hence, after 8 clock ticks, transmission and
reception of the one byte is accomplished.
SPI Engine with a
shift register and
Rx, Tx buffers
The above table shows the details of how different modes of SPI serial communication
can be achieved while changing the states of CPHA and CPOL to fulfill real-world
Applications. The next slides incorporate practical outputs of transmitting a message or data
using SPI communication.
CPOL = 0
CPOL = 1
CPHA = 0