For the final part of the wired communication protocols series, we are going to discuss SPI, also known as Serial Peripheral Interface.
SPI
SPI (Serial Peripheral Interface) is a serial and synchronous communication protocol. This protocol works best for short-range communication only. SD card modules, radio modules, RFID modules, etc. use this protocol.
Further, SPI sends any number of bits in a continuous stream, unlike UART and SPI, which sends data in a specific number of bits.
Just like I2C, SPI communication uses master and slave devices. One master device can control multiple slaves but not the other way around.
SPI is synchronous as well so it needs a clock signal. To know more about synchronous and asynchronous communication, check this previous article.
Another unique feature of SPI communication is that it needs 4 communication lines to operate.
MOSI (Master Output/Slave Input) – Master to Slave line
MISO (Master Input/Slave Output) – Slave to Master line
SCLK (Clock) – Clock signal for synchronization
SS/CS (Slave Select/Chip Select) – Used in selecting the target slave device
How SPI Works
First, the master device transmits a clock signal to the slave devices. In each cycle, it sends a bit, which dictates the speed of data transmission.
The SPI clock signal has two important properties: the clock polarity and clock phase. Clock polarity decides how bits are sampled on either the rising or falling edge of the clock cycle. The clock phase decides if sampling occurs at the first edge or second edge of the clock cycle.
2. Then, the master device drops the SS/CS pin to LOW to activate the slave.
3. Next, the master device transmits data to the slave device via the MOSI line.
4. Finally, the slave returns data using the MISO line as a response.
Advantages
- Unlike asynchronous protocols, SPI has no start and stop bits. Data continuously flows through the communication lines.
- Fast data transmission
- MISO and MOSI allows sending and receiving data at the same time
Disadvantages
- Four wires are needed to communicate
- Weak error checking since it has not ACK nor parity bit
- Does not support multiple masters
In conclusion, SPI is an asynchronous protocol that uses four lines to communicate. It has a faster data rate, but it doesn’t have proper error checking features like ACK and a parity bit. Finally, this protocol is perfect for short-range communication applications like RFID systems.
That’s it for the series! Be sure to check us out for new articles and tutorials. See you later!