Updated: Aug 29, 2020
Serial Peripheral Interface is a common protocol that is commonly used to transfer data without any interruption.
This is a fast duplex master-slave protocol and is commonly used in interfacing microprocessor and microcontrollers. SPI is commonly used in short distance communication.
Without further ado, let us look in-depth, the details about this communication.
How does SPI work?
This kind of communication is used due to simplicity and flexibility and involves a Master-Slave relationship.
There is only one master, but there are multiple slaves. SPI mainly consists of 4 pins which include MOSI (Master-out Slave-in), MISO (Master-in Slave-out), CS (Chip Select), or SS (Slave Select) and SCLK (Serial Clock).
MOSI: It can be understood from the name itself that the data is sent out by the Master and received by the Slave. So, both these pins are connected.
MISO: In this, the signal is generated by the Slave whereas the line is managed by the Master.
SCLK generates the clock signal and is given to the slave input. Using the Slave Select, the required slave can be chosen.
The data flow is controlled by the Master to the slave; i.e. during each clock cycle, we can see that one but is transmitted from master to slave and slave to master. SPI is a full-duplex communication as it completes the transfer of 1 byte after 8 clock cycles. Multiple slaves can be connected to a single master and it can generate clock signals according to the need of the slave.
We can see that there are many slaves connected to the master, but only one will be active at a time. The slave is selected using SS (Slave select) also known as CS (Chip select).
This line is active low, i.e. only if the pin is down will the chip be selected.
Modes of Operation
The Master will generate a clock signal and synchronize it with the slaves so that the data can be distributed. There are mainly two features of a clock called, Clock Polarity or Clock Phase that come into play.
Based on the CPOL and CPHA, there are 4 modes of operation, from Mode 0 to 3.
Mode 0: This mode is used when both CPOH and CPOL are zero. This is usually seen in the rising edge of the clock.
Mode 1: This mode occurs when CPOL=0 and CPOH =1. This mode of transmission occurs in the falling edge of the clock.
Mode 2: In this particular model, CPOL=1 and CPOH=0. Mode 2 occurs in the rising clock edge.
Mode 3: Mode 3 occurs when both Clock Polarity and Clock Phase are both HIGH.
SPI devices are connected mainly configured in two ways, Independent Slave Configuration and Daisy Chain Configuration. Let us take a look at these more deeply.
Independent Slave Configuration: In this configuration, the MISO and MOSI lines are interconnected and the last slave is connected to the Master's MISO.
Daisy Chain Configuration: Often referred to as the cascaded configuration, the clock and chip select are connected. The data sent from the master returns to it. The output of one slave is connected to the next device.
Advantages of SPI
The hardware interfacing in SPI is very easy to use.
A major advantage is that it supports multiple slaves in a single circuit itself.
SPI enables full-duplex communication that is not available in many other ones.
There is no need for transceivers in an SPI.
Disadvantages of SPI
SPI does not support adding nodes dynamically (hot swapping).
It does contain a protocol to check for errors.
Applications of SPI
SPI is very often used in peripherals such as sensors, ADC, and DAC. They play a vital role in real-time clocks and video games.
For the purpose of communication, they are used in Ethernet, USART, CAN, etc. Commonly used in memory devices such as Flash, SD card, and MMC, SPI is a very common yet unavoidable mode of communication.