How The SPI Protocol Works
What is SPI Protocol?
It features full-duplex communication and comes with a faster data transmission speed than I2C and UART.
And the SPI protocol is simple and easy to use. There are abundant ready-to-go libraries for using SPI on Arduino.
In addition, multiple SPI devices can be supported through chip selection, which requires relatively fewer hardware resources and low costs
The SPI interface was developed by Motorola in the mid-1980s.
But since it is a de-facto standard based on facts, there are no officially defined and adopted standards for it.
For instance, SPI communication has four transmission modes that can be freely chosen by users based on the actual situation.
It doesn't support plug-and-play(dynamic addition of nodes), and generally, there can be only one controller. Multiple devices can co-exist by chip selection, but that also means more complex connections. Besides, SPI has a high demand for wire routing because of its high transmission speed. Poor design may cause communication interrupts or data errors.
A Full-duplex Synchronous Serial Communication Protocol
Here let's get to know these keywords one by one. "Full-duplex" means it can transmit and receive data simultaneously, just like UART. So it needs at least two communication lines.
And "serial" indicates the data transmission is implemented via serial communication, which is the same as I2C and UART. By the way, there is another method for data transmission, parallel communication. Different from the serial, data bits are simultaneously transmitted through multiple communication links in parallel communication.
How Does Communication in SPI Work?
First, the controller needs to choose which peripheral it wants to talk to.
Chip select pins are connected to different peripherals correspondingly. Then a peripheral can be selected by changing its CS signal from high to low. And other unselected peripherals will ignore the incoming SCLK and PICO signals, and also not send signals via POCI. After the peripheral is determined, the data transmission starts. As mentioned before, SPI uses a clock line to synchronize the transferred data bits.
When the transmission mode is selected, signals can be transferred via PICO and POCI at the same time on the rising or falling clock edge, just like two trains running toward each other.
Here we take 8 bits as a communication period.
This data exchange will be done after one period. Then chip selection and data transmission start again. After completing the data transfer, the controller stops transmitting SCLK, and the CS signal returns from low to high.
Project
Next, let's see how to use SPI. Here we use a 6-Axis IMU module, microSD card, LCD screen and DFRobot FireBeetle ESP32-E make a recorder.
DIY A Simple Three-axis Accelerometer Data Logger
Well, that's all about SPI. Feel free to add more information in the comments. Thanks for reading. If you like the article, please forward this page to your friends if you think they are helpful!