What is the SPI Protocol and How to Debug SPI Communication?

What is the SPI protocol?

Overview of SPI

The SPI protocol was developed by Motorola in the mid 1980s to provide a language for electronic devices to communicate. The communication typically happens over short distances used on a circuit board or in a small electronic device. SPI is a simple protocol in nature used in applications where there is a relatively low amount of data transmission. Often the protocol is used for the communication between a microcontroller and sensor. Take, for instance, a motion sensor light. When the sensor is activated it communicates with a processor that then turns the light on; this communication is likely happening over the SPI bus to almost instantaneously execute the command. Applications where there is a higher data transfer rate require a faster protocol such as USB or Ethernet to keep up with the higher volume of data.

SPI Theory of Operation

SPI is a serial protocol that requires the following four wires to operate:

1. SCLK (Serial Clock): The Serial Clock wire carries the clock signal from the master device to other devices on the serial bus.
2. MOSI (Master Output, Slave Input): The MOSI wire carries data output from the master device to the slave devices on the serial bus.
3. MISO (Master Input, Slave Output): The MISO wire carries data output from the selected slave device to the master device or micro controller on the serial bus.
4. SS (Slave Select): On an SPI bus, there must be one master device, but there can be multiple slave devices. The master device can exchange data with all of the slave devices, but the slave devices can only send data to the master - not to each other. The master devices uses the Slave Select wire to select which slave device on the bus it will be communicating with before sending a data transmission.

Three of these lines are shared by all devices on the SPI bus: SCLK, MOSI and MISO. The SCLK is generated by the master device and is used for synchronization. The MOSI and MISO wires are the data lines. The direction of transfer is indicated by their names. SPI is a full duplex protocol so data is always transferred in both directions in SPI, but a SPI device interested in only transmitting data can choose to ignore the receive bytes. Likewise, a device only interested in the incoming bytes can transmit dummy bytes.

Each device has its own SS line. The master pulls low on a slave's SS line to select a device for communication. Data transmission can only occur between one slave device and the master at a time.

 

Single SPI bus with 3 slaves Each slave device requires a separate slave select signal (SS).

 

The exchange of data itself has no pre-defined protocol. This makes it ideal for data-streaming applications. Data can be transferred at high speed, often in the range of the tens of MHz. The master simply pulls low on an SS line indicating the specific slave device that the Master is expecting to either send or receive data. Pulling low on the SS wire wakes the slave up and initiates the flow of data. However, there is no acknowledgment or flow control, and the master may not even be aware of a slave's presence.

The SPI protocol is poorly suited to applications requiring multiple slaves to interact with the master at the same time. Since each slave has its own wire connecting it to the master, communication can happen much faster than other basic protocols, namely I2C, but the protocol still lacks when it comes to asynchronous transmission of data.

 

Dual Monitor Desk Setup SPI is used in LED lights, monitors and in mice and keyboards. Photo by Josh Sorenson from Pexels

SPI Applications and Devices

Devices using the SPI protocol include sensors, memory devices, clocks, and LCD screens. Other common devices include home and automotive thermometers, vehicle tire pressure sensors, and video game controllers. Devices that are capable of producing a multitude of different responses in a quick fashion often run on the SPI bus.

 

DigiKey SPI Applicaitons List of all SPI Digi-Key Applications.

 

Another common SPI application is a video game controller. When the user presses a button on the controller a response is expected to happen in-game. The protocol that is being used here is typically SPI. SPI enables developers to create an environment that feels instantaneous for the gamer.

Flash memory is another popular SPI device. The speed of the SPI protocol and the master and slave bus design make the protocol a perfect fit for data streaming to memory devices. Writing, reading, and erasing memory can be performed in a simple, but fast manner making SPI a go to protocol for memory programming.

 

Playstation 4 Dual Shock 4 wireless controller PS4 Dual-Shock controller. This controller is likely using the SPI protocol to communicate button presses.

 

Working with the SPI Protocol

Common SPI Errors and Development Issues

SPI is a great protocol to use when needing a fast, reliable, and easy-to-use protocol. Although one of the most popular serial protocols, it does come with some drawbacks as mentioned above.

One of the biggest issues arise when there becomes a need to have more than a few slave devices connected to the master. Since there is a need to have a SS (Slave Select) line for every individual slave device on the bus, the board design can get very complex. Developers often run into this issue during design implementation. They find out that the original design does not work for their application and thus need to add additional slave devices to accomplish the job. The addition of multiple new slave devices can start to complicate things.

Another issue that arises when working with SPI is cross talk or noise on the bus. Since there are multiple lines on the bus there is a high chance of interference across the wires. This issue can be alleviated with proper board designs but still remains front of mind and a common issue when working with the SPI protocol.

SPI Advantages Compared to other Protocols

SPI has many benefits when compared to other protocols. Some of the main advantages include:
• Less power consumption than I2C
• Full duplex communication
• Support for multiple slaves
• Faster speeds than I2C
• Simple implementation and low protocol overhead
• Ability to span greater distances than I2C

SPI Limitations and Drawbacks

Some of the main draw backs to SPI include:
• No flow control or acknowledgement
• Requires more signal lines than I2C
• Master must control all communication, slaves cannot talk to each other
• Board complexity arises when multiple slaves are needed
• Higher chance of noise/crosstalk due to the many wires needed

SPI Debugging Tools

When working with SPI it is important to have the right set of tools handy to ensure implementation of designs is done properly. The addition of oscilloscopes and logic analyzers are always helpful in the development process. However, these options can be cost prohibitive. There are less expensive tools available, some are software based and others are hardware based.

 

Software Engineering Computer code on a computer screen. Photo by Markus Spiske from Pexels

 

An oscilloscope is an excellent tool to use when implementing and designing the SPI bus. A scope will provide a breadth of insight into the bus including the electrical and signal characteristics of a design. However, sometimes a scope is out of reach for some developers and too expensive to have. There are some great alternatives to scopes, both in the hardware and software realm. Tools such as host adapter, programmers, protocol analyzers (hardware and software based), and logic analyzers are a few of the tools available.

The feature set of each of these devices ranges dramatically. Some tools encompass a breadth of capabilities whereas some focus on specific tasks such as only programming or sniffing.

Another thing to keep in mind is the operating systems on which these tools run. Most development tools require Windows OS. Alternatively, the Total Phase line of tools works as a truly cross platform solution. The Aardvark and Cheetah adapters, Beagle analyzers, and Promira platform work on all major operating systems including Windows, Linux, and Mac OS. Oscilloscopes typically do not require a computer OS to run as they simply operate on the built-in software/GUI.

 

Latest SPI Developments

SPI has taken on different forms and adapted over the years. The biggest evolutions in the SPI protocol come in the form of speed. Far surpassing speeds seen in I2C, SPI is now being used in implementations with speeds above 100 MHz, possible because SPI does not technically have a defined speed limit.

The protocol currently can be configured to send data in a few different formats including Single, Dual, and Quad I/O SPI. The more I/O being used to send and receive data, the faster the data transfers can happen. Dual and Quad SPI are additions to the protocol that introduce more data lanes and more data lanes mean faster communication and data transfer rates.

Single SPI

Single mode SPI works for most use cases such as rapid prototyping, device programming, and automated testing. In Single I/O, SPI operates in full-duplex mode sending data bi-directionally on the MOSI and MISO lines.

With Multi I/O SPI, systems can increase throughput by increasing the number of data wires.. Switching to Dual or Quad SPI is done via sending a command byte while in Single SPI mode. The command byte will request a response in either Dual or Quad mode.

Dual SPI

Dual SPI enables transfer rates to double compared to the single I/O. The MISO and MOSI data pins become unidirectional wires operating in half-duplex mode to send two bits per clock cycle. The MOSI line become IO0 and the MISO line becomes IO1.

Quad SPI

Quad SPI is similar to Dual I/O, but doubles the throughput again. Two additional data lines are added to transfer 4 bits every clock cycle. The data lines are now IO0, IO1, IO2, and IO3.

The protocol continues to adapt with the introduction of Octal SPI. Octal SPI enables the use of eight I/Os. This doubles the available lanes from Quad SPI meaning Octal SPI will introduce speeds never before seen on the SPI bus. Over the next few years we will see Octal SPI make its way into applications and its use become more main stream.

 

Graphic of the bus layout for an Octal SPI configuration. Graphic of the bus layout for an Octal SPI bus configuration.

 

Total Phase SPI Tools

Total Phase has a variety of different tools that interface with the SPI protocol. All of the SPI tools that Total Phase offers will fall into two different categories: host adapters and protocol analyzers. Host adapters allow users to interface directly with the SPI system and program SPI devices. These tools allow for interaction with the SPI protocol. Whereas the protocol analyzers do not interact with the data as much as they do monitor the traffic that is happening on the bus. Host adapters allow users to interact with the data whereas protocol analyzers allow the user to non-intrusively monitor the data in real time.

Total Phase Host Adapters

Total Phase offers host adapters including the Promira Serial Platform, Aardvark I2C/SPI Host Adapter, and Cheetah SPI Host adapter. All three of these tools interface with the SPI protocol with the main differentiators being in terms of speed and expandability.

Aardvark product image
Promira Serial Platform Promira product image
Cheetah product image

 

The primary difference among these tools is speed. The Aardvark I2C/SPI Host Adapter is able to act as an SPI master at up to 8 MHz and slave at up to 4 MHz. For higher speeds, the Promira platform and Cheetah adapter offer more options. The Cheetah SPI Host Adapter is able to act as a SPI master at up to 40 MHz, but does not offer any slave capabilities. The Cheetah adapter is well-suited to SPI programming applications as it features a High-speed USB connection with a pipelined architecture for maximum throughput. For maximum master and slave speeds, the Promira Serial Platform can act as an SPI master at up to 80 MHz and slave at up to 20 MHz.

 

Promira Applications Comparison Chart

 

Another differentiating factor among these tools is their functionality. All three tools can emulate an SPI master from 8 MHz all the way up to 80 MHz. However, only the Aardvark adapter and Promira platform are capable of emulating a slave device at maximum speeds of 4 MHz and 20 MHz respectively. The Cheetah adapter is strictly an SPI master device and does not have any SPI slave capabilities.

The Promira platform also offers an integrated level shifter allowing it to change voltage levels via software control. It also provides up to 8 slave selects and up to 16 GPIO(s). The Aardvark adapter only supports one slave select and Cheetah adapters supports three slave selects. The Aardvark adapter can enable a maximum of 6 GPIOs while the Cheetah adapter does not have any GPIO capability. The Aardvark comes with the ability to interface with I2C as well whereas the Promira and Cheetah do not support I2C natively. The Promira requires an additional application and the Cheetah simply doesn’t have the capability built into the hardware.

Benefits of the Promira Serial Platform

The Promira Serial Platform is the most versatile tool Total Phase has ever made. Being a platform-based tool means that the adapter is never limited in capability. If more functionality is needed simply install the correct application to get the feature set needed to complete the task at hand. This is the most flexible development tool around. Some additional features that the Promira platform boasts are:

Integrated level shifting - work with signal voltages ranging from 0.9V - 5.0V without additional accessory boards or external cabling.
Remote control - expand the range of production and prototype units beyond interfacing with units remotely.
More target power - provide up to 200 mA to target devices, which in many cases, eliminates the need for an external power source.

Promira Serial Platform

 

Benefits of the Aardvark I2C/SPI Host Adapter

The Aardvark I2C/SPI Host Adapter is the most popular Total Phase development tool. When interfacing with SPI, the Aardvark adapter provides a breadth of capabilities. Some additional SPI features include:

• Operates in Master or Slave mode
• Up to 8 MHz Master signaling rate
• Up to 4 MHz Slave signaling rate
• Offers up to 6 GPIO
• I2C functionality included

Aardvark I2C/SPI Host Adapter logo

 

Benefits of the Cheetah SPI Host Adapter

The Cheetah™ SPI Host Adapter is a high-speed SPI adapter that is capable of communicating over SPI at up to 40+ MHz. The Cheetah adapter is specifically designed to communicate with high-speed, SPI-based Flash memory. It is an ideal tool to develop, debug, and program SPI-based systems.

• High-Speed SPI Master signaling at up to 40+ MHz.
• Transaction Queuing for Maximum Throughput
• Supports up to 3 slave devices

Graphic of Cheetah SPI Host Adapter

 

Total Phase Protocol Analyzers

Total Phase also offers a protocol analyzer that provides in-depth information for the SPI bus. The Beagle I2C/SPI Protocol Analyzer analyzes the SPI bus by simply attaching to the SPI lines. The analyzer will capture and stream all of the traffic happening across the system in real time. As communication is happening on the bus, the data will instantly be displayed in the Data Center Software.

Beagle I2C/SPI Protocol Analyzer Data Center Software

 

Being able to analyze the SPI bus in true real time provides time saving advantages. Unlike other bus sniffers that require long buffers and download times, the Beagle analyzer presents the data to user as the transaction is taking place on the bus.

Benefits of Beagle I2C/SPI Protocol Adapter

The Beagle I2C/SPI Protocol Analyzer is a non-intrusive device that monitors the SPI bus up to 24 MHz. Captured data is streamed via High-speed USB directly to a computer. The amount of data captured is limited only by the amount of RAM available on the PC. The versatile Beagle analyzer is the ideal tool for the embedded engineer who is developing an SPI-based product.

Graphic of Beagle I2C/SPI Protocol Analyzer logo

For more information on Total Phase solutions and tools see the below linking articles.