Serial Peripheral Interface (SPI)

Pages
Contributors: MikeGrusin
Favorited Favorite 96

Resources and Going Further

Tips and Tricks

  • Because of the high speed signals, SPI should only be used to send data over short distances (up to a few feet). If you need to send data further than that, lower the clock speed, and consider using specialized driver chips.

  • If things aren't working the way you think they should, a logic analyzer is a very helpful tool. Smart analyzers like the Saleae USB Logic Analyzer can even decode the data bytes for a display or logging.

SPI under Saleae Logic Analyzer

Advantages of SPI:

  • It's faster than asynchronous serial

  • The receive hardware can be a simple shift register

  • It supports multiple peripherals

Disadvantages of SPI:

  • It requires more signal lines (wires) than other communications methods

  • The communications must be well-defined in advance (you can't send random amounts of data whenever you want)

  • The controller must control all communications (peripherals can't talk directly to each other)

  • It usually requires separate CS lines to each peripheral, which can be problematic if numerous peripherals are needed.

Further Reading

Check out the Wikipedia page on SPI, which includes lots of good information on SPI and other synchronous interfaces.

This page presents a more correct way to set up an SPI network amongst your embedded devices, particularly for use with an Arduino microcontroller.

A number of SparkFun products have SPI interfaces. For example, the Bar Graph Breakout kit has an easy-to-use SPI interface that you can use to turn any of 30 LEDs on or off.

Other communication options:

Serial Communication

Asynchronous serial communication concepts: packets, signal levels, baud rates, UARTs and more!

Analog to Digital Conversion

The world is analog. Use analog to digital conversion to help digital devices interpret the world.

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

AST-CAN485 Hookup Guide

The AST CAN485 is a miniature Arduino in the compact form factor of the ProMini. In addition to all the usual features it has on-board CAN and RS485 ports enabling quick and easy interfacing to a multitude of industrial devices.

Now that you’re a pro on SPI, here are some other tutorials to practice your new skills:

MP3 Player Shield Music Box

Music Box Project based on the Dr. Who TARDIS.

Using the Serial 7-Segment Display

How to quickly and easily set up the Serial 7-Segment Display and the Serial 7-Segment Display Shield.

SparkFun BME280 Breakout Hookup Guide

A guide for connecting the BME280 sensor to a microcontroller, and for using the SparkFun Arduino library.

Raspberry Pi SPI and I2C Tutorial

Learn how to use serial I2C and SPI buses on your Raspberry Pi using the wiringPi I/O library for C/C++ and spidev/smbus for Python.