Integrated circuits, Microcontrollers, Telecomunications

SPI communication protocol

The SPI, an abbreviation of Serial Peripherical Interface, is another communication protocol used in microcontrollers and peripherical.

How SPI works?

Motorola implemented this standard for the first time in 1970. Just like I2C, it’s a synchronous serial communication protocol. In this communication method, transmitting and receiving devices must have their clock signals synchronized, i.e., must change bits at the same time. A solution is to send the transmitter’s clock signal to receivers.

data transmission on SPI
On SPI, data are continually transmitted. Without the necessity of bits to indicate beginning and end of a message. Source: teachmemicro.com.

SPI operates in full-duplex mode, i.e., both sides of communication can exchange information between themselves at the same time.

interface between chip and output pin on SPI
On interface between the integrated circuit and output terminal, 2 MOSFETs determine if pin’s signal will be 1 level (“HIGH”, on the left) or 0 (“LOW”, on the right). Source: Open4Tech.
A pulse curve on push-pull configuration, used by SPI. In comparison with pull-up or open drain configuration, present on I2C protocol. Source: embarcados.

Serial and parallel interface

series and parallel transmission
In a serial interface communication, as in SPI case, bits are transmitted one at a time for each clock pulse. The advantage is that requires less space. In a parallel interface, many bits can be transmitted at same time. The speed is higher, but each bit needs a physical channel for transmission. Source: Adafruit.
shift register for SPI
Master and slave must have an 8-bit shift register for communication. Source: fastbitlab.com.

The SPI bus

The communication interface SPI requires 4 wires between master (sends commands) and slave (receives commands).

  • SCLK: serial clock signal. Both must have the same signal because this interface is synchronous.
  • MOSI (Master Output Slave Input): communication channel for the master or controller to send data to the slave or peripheral.
  • MISO (Master Input Slave Output): channel to peripheral send data to controller.
  • SS or CS (Slave/Chip Select): master must send a signal on the “LOW” level to communicate with a receiver. Won’t have exchange information if its on “HIGH” level or 1.
Source: Circuits Basics.
SPI communication bus with a master and many slaves.
To connect with more than a peripheral, the controller must have more than a single CS pin. Source: ITP Physical Computing.

Clock parameters

It’s possible to adjust two parameters on the clock channel to configure SPI bus: polarity and phase. Clock polarity (CPOL) determines if clock’s idle state will be “1” or “0”. While clock phase (CPHA), determines if data sampling is done on clock rise or clock descend, this parameter also depends on polarity.

SPI clock parameters.
The four adjustment modes of clock parameters. Source: StackExchange.
SPI sampling.
Example of SPI data sampling. Source: Stack Exchange.

Advantages and disadvantages in relation to I2C

The advantages of SPI are:

  • It doesn’t need addressing bits, making transmission simpler.
  • Higher transmission rate than I2C.
  • Two-way communication (full-duplex). While I2C is half-duplex, it’s two-way also, but the information flux in a direction has to wait until the transmission in the opposite direction ends.
  • Has lower power consumption.

The disadvantages:

  • This interface requires 4 wires for each peripheral, while I2C only needs two.
  • Only one master is viable.
  • There’s no error connection.
  • There’s no verification of data reception.

About Pedro Ney Stroski

Leave a Reply

Your email address will not be published. Required fields are marked *