Synchronous serial communication protocol used for short-distance communication in embedded systems.

It’s a four-wire (plus ground) interface commonly used to connect microcontrollers to various peripheral devices like sensors, memory chips, displays, and other integrated circuits.

The Four Lines

MISO (Master In Slave Out)

The MISO line carries data from the slave to the master. The slave sends the data to the master via this line.

MOSI (Master Out Slave In)

The MOSI line carries data from the master to the slave. The master sends data to the slave via this line.

SCK (Serial Clock)

The clock signal is generated by the master to synchronize data transfer. It dictates when the data bits on MISO/MOSI lines should be sampled or shifted.

SS/CS (Slave Select/Chip Select)

The CS line is used to select which slave device the master wants to communicate with. The master pulls the CS line low (active low) to select a slave, while other slave devices are kept high (inactive).

Advantages of SPI

  • Higher Throughput than Protocols like I2C (reaching several MHz to tens of MHz)
  • Full Duplex Communication
  • Simple hardware implementation as it uses basic shift registers
  • No addressing overhead as the protocol itself doesn’t require addresses
  • Flexible word size

Limitations of SPI

  • More I/O pins required compared to other protocols like I2C
  • No built-in flow control or acknowledgment mechanism
  • No standardized specification which leads to variations between manufacturers
  • Shorter range than some other protocols due to lack of noise immunity
  • No error checking built into the protocol
  • No multi-master support in standard implementations