The serial peripheral interface (SPI) is a digital communication protocol for two or more devices as the UART. Here, we will focus only on the SPI communication between two devices. Hence, one device will be the transmitter and the other receiver. Different from the UART, the SPI is a synchronous communication protocol. Besides, communication between the transmitter and receiver is duplex. In other words, data is transmitted and received at the same time in the SPI. Therefore, the SPI communication uses four wires. Two of these wires are for data transfer. One wire is used for common clock signal (for synchronization). The fourth wire is used to enable (select) signal to be explained later.

Being synchronous, the SPI needs a common clock signal generated by either the transmitter or receiver. Clock generating side is called leader. The other side is called follower. The roles are generally called master and slave in literature. However, we prefer leader and follower naming on our website. Therefore, we will use the terms forward. As a result we can have leader-transmitter, leader-receiver, follower-transmitter, and follower-receiver options.

Working Principles of SPI

The working principles of the SPI are simpler than the UART. To understand them, we introduce the data format, connection diagram, transmission and reception operations, and timing in the following parts.

Data Format

Different from the UART, data packet size is not constant in the SPI. This is an advantage since the user can select the packet size as he or she desires. Moreover, the dedicated common clock and enable signal avoid using start and stop bits in the UART. The only requirement here is the need for determining the data packet size. Hence, the transmitter and receiver can understand each other.

Connection Diagram

The SPI uses a dedicated clock line, two data lines (one for transmitter, one for receiver), and a select (enable) line as mentioned in the previous section. Here, the clock signal is denoted by SCLK. The leader output, follower input is denoted by MOSI. The leader input, follower output is denoted by MISO. Select is denoted by SS which is used byt the leader to wake up the follower. The select line is also used when more than one follower is connected to a single leader.

Transmission and Reception Operations

In the SPI, the data transmission and reception is controlled by the leader through SCLK and SS signals. When there is no transmission, SS stays at logic level 1 and SCLK stays either at logic level 0 or 1 depending on the SPI mode. The modes of the SPI and their timing diagrams will be discussed later. The SPI Communication starts when the leader wakes the follower by setting SS to logic level 0. Next, the leader and follower start interchanging data in every clock cycle set by SCLK. Here either the leader sends a bit through MOSI line or the follower sends a bit through MISO line. The SPI mode also determines if data will be sent on the rising or falling edge of SCLK. After all bits are transferred, the common clock stops and leader deselects and the follower by changing SS to logic level 1.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.