Electronics are everywhere. Many times, as frequent users, we do not even notice a “paradigm change” in the things we use on regular basis. We use a fridge, but we do not care that there is a microcontroller (MCU) and a set of sensors instead of a basic thermostat. We use a tablet with a touchscreen, but we do not care how the screen-tap information is transmitted to the MCU. We use SD cards to store photos and movies in our smartphones, cameras, and other portable devices, but the card’s interface is a big mystery for many — at least for those who have never dug into the details.
Every electronic device must be equipped with an MCU — also called the device’s brain. An MCU is a tiny computer fabricated on a single chip. It contains at least one central processing unit (CPU), memory, and input/output peripherals. When we talk about peripherals, the serial peripheral interface (SPI) becomes crucial. SPI plays an essential role enabling fast, reliable, and simple short-distance communication. It is also simple enough to implement and has a low resource usage. This is reflected in the statistics: EE Times Asia shows the most popular MCUs, and each and every one of them is equipped with SPI controller; the same in Electronics-Lab.com’s ranking and other rankings. So it’s obvious that SPI is a must for every MCU.
This article focuses on the most important details of the modern SPI interfaces, which are improved by many useful features. But to start, let us discover the history of the modern SPI interface, because even the old, most basic SPI interfaces are still in use.
Brief history
SPI was developed by Motorola in the 1980s. It is a synchronous serial communication interface used in embedded systems. The single SPI specification (the first specification) describes the master-slave architecture (full-duplex), typically with one master device and multiple slave devices. It is also called the four-wire serial bus:
- SCK — serial clock line (master output)
- nSS — slave select line, active on low logic level (master output, one for each underlying slave)
- MISO — serial data line: master in, slave out (master input, slave output)
- MOSI — serial data line: master out, slave in (master output, slave input)
Why did SPI become so popular? Mainly because of its simplicity. There are no start nor stop bits, there is no parity like in UART bus, and it enables higher transfer rates than I2C. There are plenty of pros.
The logic resources needed to implement SPI are very few: Single SPI simultaneous transmission and reception synchronized by serial clock can be modeled as two shift registers in a loop, as it has been presented below.
In reality, the SPI controller internal architecture is much more complicated than it has been shown in Figure 1, featuring more control registers, port control logic, and interrupt control. The example architecture can be found in Motorola’s SPI standard, “SPI Block Guide.”
The clock phase and polarity are configurable. There are four transfer formats available:
CPOL defines whether SCK is low (0) or high (1) when bus is idle (nSS is high).
CPHA defines whether the first (0) or second (1) SCK edge after nSS has been asserted (nSS is low) is used to sample data.
If data is sampled at the rising SCK edge, then shift occurs at the falling SCK edge.
If data is sampled at the falling SCK edge, then shift occurs at the rising SCK edge.
The shift registers are both 8 bits (in master and in slave). Data is shifted out with the most significant bit first and shifted in with the least significant bit first. The transmission is full-duplex because both the master and slave send and receive data simultaneously.
MISO and MOSI lines can be combined into one bidirectional line, but the transmission will be reduced to half-duplex. In this case, only three wires are needed for SPI transmission/reception.
There are many implementations of SPI bus controllers available on the market. Just as an example, DCD-SEMI’s DSPI is a fully configurable SPI master/slave device. It is flexible enough to interface directly with numerous standard peripherals like memories, sensors, etc. The IP is easy to use and utilizes a low amount of logic resources — just as the SPI should be.
Multi-line SPI
SPI is frequently used in communication with serial memories. The memory size can be large, which enforces the need of faster transfers. SCK cannot increase infinitely, so the first thought is to increase the number of data lines, not to unnecessarily increase the number of wires. it is better to stay with the half-duplex transmission.
As the first, dual SPI has been introduced. MOSI has become SIO0 (Serial I/O 0) and MISO has become SIO1. SIO0 carries even bits and SIO1 carries odd bits. The bus throughput becomes doubled.
Then the quad SPI has been mastered. New data lines have been added: SIO2 and SIO3. The bit transmission scheme looks as follows:
The bus throughput becomes doubled again, and each data byte can be sent in only two SCK cycles.
The SPI transfer from/to serial memory consists of several phases: Instruction (command), Address, Data, and, optionally, Checksum. Some commands are required to be sent in single SPI mode, while Address and Data are sent in multi-IO mode.
Further extending quad SPI, some devices increase the transfer rate by using double-data–rate (DDR) transmission, wherein data lines are sampled both on the rising and falling edge simultaneously, so every data byte is sent in just one SCK cycle. An example is shown in Figure 5.
One could ask: If we are already using four data lines, why not expand further? So thought the engineers who introduced octal SPI. In single-data–rate (SDR) mode, 1 byte is sent in one SCK cycle, and in DDR mode, 2 bytes are sent in one SCK cycle. The bandwidth increases significantly. An example is shown in Figure 6.
The transfer format shown in Figure 6 has its limitations. Instruction is sent repeated, as 2 bytes, to preserve an even number of bytes in transfer, because sampling is done on every SCK edge. Alternatively, the command can be sent in SDR mode. Address and Data phases must also contain an even number of bytes.
By now, the CPOL and CPHA settings have lost their meaning. Octal SPI DDR transfers are conducted only in SPI mode 0.
For HDL designers, it’s common to develop backward-compatible SPI master/slave controllers. DCD-SEMI finds customer’s interest in the DQSPI that supports single, dual, and quad SPI transfers, while DOSPI supports single, dual, quad, and octal SPI transfers. Both support DDR transfers, support multiple SPI slaves, implement a dedicated FIFO memory, and are available with the most common CPU bus interfaces. In single SPI mode, all of Motorola’s SPI configurations are supported.
eXecute In Place
Thanks to DDR and quad/octal transfers combined with high SCK frequency, it became possible to execute programs directly from a serial memory instead of copying the program memory into RAM. The program code must be stored in nonvolatile memory and the serial flash memory is cheaper than a parallel. The SPI controller in eXecutive In Place (XIP) mode is considered a bus bridge: From the “CPU’s point of view,” it is a simple memory that can be accessed parallel, and from the “SPI memory’s point of view,” it is just an ordinary SPI master. The CPU read transfers are performed with zero latency, if the program is executed linear (address after address) or the jump does not cross boundary of memory page, stored in controller’s FIFO memory. Also, in a typical embedded system, the MCU does run on significantly lower frequency than the SPI controller, so the data is available immediately, even if the next memory page has to be read.
In XIP mode, there is also available the regular register access to SPI controller. This mode is also used to configure the IP’s internal registers.
Typically, XIP is used in First Stage Boot Loader, e.g., in embedded systems, Linux OS, BIOS, etc. The SPI controller is preconfigured on power-on reset, and after the reset is deactivated, it starts reading the first memory page. There are also attempts to prepare file systems based on XIP.
The aforementioned DQSPI/DOSPI, as well as the latest SPI flash controller (DFSPI) are also available with the XIP interface. This ensures optimal system performance and wide configuration options.
Recently, another interesting feature can be found in SPI controllers, like in the DFSPI. For best performance and lowest software overhead, the automatic configuration feature can be used. The SPI controller is equipped with additional small memory, which acts as the lookup table, storing predefined device configuration. The memory content is prepared before the synthesis and implementation, or in a more advanced solution, it can be modified like an ordinary internal register. After writing Instruction/Command into the SPI controller, the device is automatically configured. The configuration may cover:
- Command code
- Addressing mode
- Transfer type — transmission or reception
- Latency/dummy cycles
- SPI mode: single, dual, quad, octal
- SDR/DDR
- Other
eXpanded Serial Peripheral Interface
Based on the information from this article, we can see how handy SPI is. JEDEC created a new standard above SPI, with limited backward compatibility. The standard defines commands for general-purpose read and write of any device, which helps in system development. eXpanded Serial Peripheral Interface (xSPI) helps to develop device-provider–independent applications.
xSPI enables flexible configuration of SPI transfer mode (single, dual, quad, octal) and SDR/DDR mode. Instruction, Address, and Data can all be independently performed in one of the modes as follows:
- Instruction phase — Address phase — Data phase
- Width (number of data lines used)
- 1: SIO0
- 4: SIO0, SIO1, SIO2, SIO3
- 8: SIO0, SIO1, SIO2, SIO3, SIO4, SIO5, SIO6, SIO7
- Data rate options: S for SDR, D for DDR
For example, a 4S-4D-4D can be performed.
HyperBus became part of xSPI in 2017. It has been named xSPI type 8D-8D-8D Profile 2.0.
In both HyperBus and xSPI, high clock rates can be achieved by using a separate clock signal for transmission (master-generated) and for reception (slave-generated/returned with internal delay). This provides best timing reference and is source-dependent. The data and strobe must be synchronous, while the strobe and SCK have no phase dependency.
The DFSPI is one of the SPI controllers already supporting xSPI.
It’s worth mentioning that recently, a new Xccela Consortium has been established. The new standard is xSPI-compliant at the physical layer. It focuses on the plug-and-play compatibility between products and provides complete device specifications and guidelines for designers.
Serial bus replaces parallel bus
Enhanced Serial Peripheral Interface (eSPI) uses the same timing and electrical requirements as regular SPI, but it is designed to replace the deprecated LPC bus, which has replaced the ISA bus on the PC’s motherboard. The LPC messages and much more are replaced by in-band SPI transfers. eSPI is low-power, energy-efficient, and configurable bandwidth bus. Even though at the physical layer, the eSPI uses the same SPI bus, the protocol and requirements are different.
First of all, eSPI introduces a new signal “alert,” which works like an interrupt request from the slave to the master. If the master asks for data and the data cannot be immediately returned, the transmission is ended and the slave requests transmission completion after the data has been prepared. Alert can only be driven when bus is idle (CS is high).
Each eSPI transfer consists of a Command and Response phase divided by a Turnaround phase. In Command, the master drives information on the bus. In Turnaround, all I/O lines are tri-stated, and the bus mastering is given to the slave. In Response, the slave drives information on the bus. Both Command and Response are supervised by CRC. In Response, the eSPI slave also returns the internal slave status register state.
Without going deeper into the details of the eSPI bus, we can see how different it is — also a good example of the usage of the SPI bus. xSPI gathers all the previous SPI standards together, while eSPI is a totally different standard. eSPI has been created by Intel and is best tailored for motherboards with Intel CPU (Intel architecture Skylake U or newer).
eSPI standard goes back to 2016. As we can see in different vendors’ portfolios, it is not so common like xSPI, but DCD-SEMI has already got a dedicated DESPI controller available.
Summary
SPI has evolved over the last four decades — from a basic concept to an advanced serial bus. But one thing remains the same: It is commonly used and can be found everywhere. But before you use an SPI controller in your next project, it will be worthwhile to compare the available IPs and to choose the best-fitting one in your design. As an example, you can take a look at the table below. All SPI IP cores, but the functionality differs a lot.