SPI (Serial Peripheral Interface)

Dilarakaplan
3 min readMar 14, 2024

--

What is SPI?

SPI is a serial communication protocol, as the name suggests. It is synchronous communication. It means that, in order to send data, a clock pulse is required.

This communication is full-duplex. With full-duplex communications, data can be sent and received simultaneously.

Structure of SPI

There is a master-slave relationship between devices in SPI communication. The master acts as a regulatory device, and the slave works as per the instructions received from the master.

Master-Slave Relationship

SPI uses 4 signal lines (MISO, MOSI, SCLK, SS/CS)

  1. MISO (Master Input Slave Output): Answer is sent from slave to master in this line
  2. MOSI (Master Output Slave Input): Data is sent from master to slave using this line
  3. SCLK (Serial Clock): It is created by the master, it provides synchronization. Data is sent synchronously with these clock pulses.
  4. SS/CS (Slave Select/Chip Select): Slave select line, the master can choose the slave that master wants to communicate with. For this, the master sets the SS line of the slave to a low voltage level.

How Does SPI Work?

We can briefly explain the working principle of SPI as follows:

Firstly, the master creates the clock signal, then it sets the SS pin to low voltage level to enable the slave. After data is sent by the master to the slave as one bit using the MOSI line. If the master needs the answer, the slave sends the answer to the master as one bit across the MISO line.

SPI Modes (Clock Phase and Clock Polarity)

SPI works in 4 different modes. These modes depend on clock polarity (CPOL) and clock phases (CPHA). While CPHA determines when data is captured or altered in relation to the clock signal, CPOL determines the idle state of the clock line (high or low).

Mod-0 (CPOL=0, CPHA=0): Data is sampled at the rising edge and altered at the falling edge.

https://soldered.com/learn/what-is-the-spi-communication-protocol/
Mod-0

Mod-1 (CPOL=0, CPHA=1): On the falling edge, the data is sampled, and on the rising edge, the data is changed.

Mod-1

Mod-2 (CPOL=1, CPHA=0): On the falling edge, the data is sampled, and on the rising edge, the data is changed.

Mod-2

Mod-3 (CPOL=1, CPHA=1): Data is sampled at the rising edge and altered at the falling edge.

Mod-3

References

  1. What is the SPI communication protocol — Soldered Electronics
  2. Understand SPI Communication Protocol (justdoelectronics.com)
  3. SPI Simplifies Device Communication | DigiKey
  4. SPI Haberleşme Protokolü Nedir ve Nasıl Gerçekleşir? — Arduino Destek
  5. Understand SPI Communication Protocol (justdoelectronics.com)
  6. SPI Simplifies Device Communication | DigiKey

--

--