Hi there, I’m back with another interesting article, on Basic Electronics. Today we are going to discuss SPI Protocol along with its composition and transmission process. We used the SPI communication protocol in many places where we have to control many devices using a single master device. for example, if you have to broadcast the msg to many channels you can connect all the devices using the SPI protocol.
- SPI-Serial Peripheral Interface is the most common and mostly used interface for communication of devices and for High-Speed Data Transfer
- Most of the devices, especially the Displays and Fast data processing Devices, use this interface. Although this interface is good for high-Speed data transfer to operate fast refresh rate displays, HDMI is preferred.
- This communication can either be single or multiple, as it all depends on the user’s preference and need.
What is SPI Protocol?
- SPI stands for Serial Peripheral Interface, which is a Synchronous data transmission protocol, unlike UART. It is the most famous for high-speed communication among I2C, UART & SPI.
- SPI is usually 4 wire transmission among which one is a clock line that is generated by the microcontroller, or in the case of multiple microcontroller configurations by the master.
- The Other two wires act like Rx & Tx of the UART communication and allow the flow of data in either direction respectively. But the connection must be made by keeping in mind the Master and slave configuration.
- Lastly, The pin which tells the devices when to listen to data or not is the CS pin, which acts as the on/off toggle switch for listening to data sent by the Master.
- In this communication, you have to make sure that the logic level used by both devices must be the same. Else the data transmission error may occur, or even you may damage either of the devices connected in the transmission process.
- The master should be one for correct transmission and with any confusion of data, but the slaves can be more as it depends on user need. Also, the connection must be made according to the preferred connection, which is discussed further.
SPI communication protocol is similar to the I2C protocol only there is a difference which you can realize when you read the I2C protocol article on our website.
SPI Data Transmission
- In SPI Protocol SPI Data transmission usually requires 4 wires MISO, MOSI, SCK & CS. The number of wires can increase or decrease according to the requirement of the sensor, like in the case of Displays.
- MISO – Master In/ Slave Out:- The signal to this pin is sent by the slave, but it is according to the clock signal generated by the master.
- MOSI – Master Out/ Slave In:- The signal to this pin is sent by the master and according to the clock signal generated by the master.
- SCK – Serial Clock:- This pin holds the Serial Clock signal, usually generated by the master. This signal is responsible for all the processes. Like the speed of the data and data bit size.
- CS – Chip Select:- This pin act like a toggle switch which is usually used in the case of multiple slave devices. This pin helps the master to decide to allow which slave to read data.
There are two types of connection that are used to connect multiple devices:-
Independent Slave Configuration
- In this configuration, all the slaves are connected to the same MISO, MOSI & SCK Pins while the CS pins for all the slaves are different.
- The Speed for all the slaves will be the same and cannot be changed during communication, so make sure to use devices that are compatible with each other
- Each slave is assigned a different CS pin, which allows the microcontroller to select the slave to which data is to be sent, so select a different CS pin for each slave.
Daisy Chain Configuration
- In this SPI Protocol configuration, the slave is connected in series as their DAT or MISO and MOSI line connected in series as shown in the above diagram.
- The MOSI pin of the microcontroller is connected to the MOSI pin of the first slave, and the MISO of the microcontroller is directly connected to the MISO pin of the last slave.
- In all, the slave CS and SCK pins are connected in parallel to the microcontroller, and the MISO and MOSI pins of the slave are interconnected as in the above diagram.
We have made many projects on the SPI protocol and shared the link given.
- SPI modes are nothing but the way, how the edge of the clock signal is arranged, and the data is sampled or shifted. This is important as different devices require different SPI modes to work.
- This is determined by selecting the Clock Polarity(CPOL or CKP) and the Clock Phase(CPHA). These can be clearly explained further by these tables and images.
- Out of these 4 the most common one is the SPI Mode0. This is used by most of the SPI devices, as this is most common and most compatible.
|CPOL||CPHA||Clock polarity |
( At Start of Data)
|0||0||0||Logic LOW||Rising Edge|
|1||0||1||Logic LOW||Falling Edge|
|2||1||0||Logic HIGH||Rising Edge|
|3||1||1||Logic HIGH||Falling Edge|
We have explained the SPI protocol above if still you have any doubt you can ask in the comment section.