SPI communication Protocol Introduction and Basics (original) (raw)

In this guide on SPI communication, you will grasp the concepts of SPI communication protocol which is also known as Serial Peripheral Interface, is a digital communication protocol that is used to transfer data serially (one bit at a time) between two or more digital devices like microcontrollers, microprocessors, or other devices. Many analog devices like analog to digital converts, analog sensors, temperature sensors, and data converters also provide interfacing mode based on SPI communication. You can go through these two articles to get more practical exposure to this communication interface:

The most commonly used devices which communicate with microcontrollers over SPI bust are:

SPI Connection Between Two Devices

It is Full duplex synchronous communication. Both Master and Slave can exchange data with each other on the rising and falling edge of the clock signal. The Block diagram below shows interfacing with one Master and one Slave. SPI interface consists of either three or four signals. But in this article, We will see a general 4 wire interface.

SPI communication interface

The functionality of each signal is given here.

In short, in this communication protocol, devices exchange data in master/slave mode. The master device is mainly responsible for the initiation of the data frame. The master device also selects the slave device to which data need to be transferred. Chip select line is usually used to identify or select a particular slave device.

Whenever a master device read to transmit data to slave or want to receive data from the slave, the master does so by activating the clock signal. Every master device sends data on the MOSI line and receives data through another line that is MISO. SPI communication pins

SPI Working Operation

As we mentioned earlier, the SPI bus consists of a single master and multiple slave devices. But SPI bus can be used in different configurations like a single master and a single slave as shown in the diagram below.

For some SPI devices, if only a single slave is used, a chip select pin can be connected with active low signal, but this feature varies for different SPI based devices.

SPI Protocol Data Transmission

Now let us discuss the transmission of data through SPI protocol in a step by step manner.

SPI Protocol Data Transmission 1

SPI Protocol Data Transmission 2

SPI Protocol Data Transmission 3

SPI Protocol Data Transmission 4

Different Configuration Modes of SPI Bus

  1. Typical SPI bus
  2. Daisy chained SPI bus

In typical SPI bus mode, only one master device can control multiple independent slave devices. However, an independent chip select signal is required for each slave device which is provided by the master device as shown here. The obvious pitfall of this configuration is that the number of chip select pins required with the master devices should be equal to the number of slave devices we want to use. This is also known as an independent slave configuration.

Typical SPI bus mode

The Daisy chained SPI bus configuration is an improved version of the above-given model. It improves the previous configuration mode by reducing the drawback of typical SPI bus mode. In this mode, slave devices act like cooperative devices instead of independent devices. But the constraint of GPIO pins makes it difficult to implement a typical SPI bus method for embedded systems applications like with microcontrollers. Therefore, another method is daisy-chained mode which propagates data through devices connected in the chain or in series as shown in the figure.

In this configuration, only one chip select signal from the master device controls all slave devices and also all slave devices work on the same clock signal. But only the first slave device gets data from the master device directly, all other slave devices receive data on their input pin from the subsequent slave device as shown in the figure above. . Some devices come with Daisy chained and some with typical SPI mode configuration.

SPI Module Internal Structure

The data transmission between a master and a slave device generally consists of two shift registers as shown in the diagram here. These shift registers are usually of 8 bits size for both the master and the slave device.

SPI communication data transmission

Clock polarity and Phase

As I mentioned earlier, the master device is responsible for setting the clock frequency. But other than clock frequency, the master device also configures two things such as clock polarity and phase according to the data transmission.

Two registers/names are most commonly used and adopted by maximum vendors namely CPOL and CPHA. These names are just the conventions just by the most SPI devices vendors. The timing diagram of SPI communication along with clock phase and polarity signals are shown below.

According to the values of these two bits, SPI communication can be in four modes given in this table.

Advantages

Disadvantages

SPI Communication Applications

Why SPI communication is used?

Other Serial Communication Tutorials:

Microcontroller based Communication Tutorials: