Serial Peripheral Interface (SPI) is a
de facto standard
A ''de facto'' standard is a custom or convention that is commonly used even though its use is not required.
is a Latin phrase (literally " of fact"), here meaning "in practice but not necessarily ordained by law" or "in practice or actuality, ...
(with many
variants) for
synchronous serial communication, used primarily in
embedded systems
An embedded system is a specialized computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is em ...
for short-distance
wired communication Wired communication refers to the transmission of data over a wire-based communication technology ( telecommunication cables). Wired communication is also known as wireline communication. Examples include telephone networks, cable television or i ...
between
integrated circuits
An integrated circuit (IC), also known as a microchip or simply chip, is a set of electronic circuits, consisting of various electronic components (such as transistors, resistors, and capacitors) and their interconnections. These components a ...
.
SPI follows a
master–slave architecture,
where a master device
orchestrates communication with one or more slave devices by driving the
clock
A clock or chronometer is a device that measures and displays time. The clock is one of the oldest Invention, human inventions, meeting the need to measure intervals of time shorter than the natural units such as the day, the lunar month, a ...
and
chip select
Chip select (CS) or slave select (SS) is the name of a control line in digital electronics used to select one (or a set) of integrated circuit
An integrated circuit (IC), also known as a microchip or simply chip, is a set of electronic cir ...
signals. Some devices support changing master and slave roles on the fly.
Motorola
Motorola, Inc. () was an American multinational telecommunications company based in Schaumburg, Illinois. It was founded by brothers Paul and Joseph Galvin in 1928 and had been named Motorola since 1947. Many of Motorola's products had been ...
's original specification (from the early 1980s) uses four
logic signals, aka lines or wires, to support
full duplex communication. It is sometimes called a ''four-wire''
serial bus to contrast with
three-wire variants which are
half duplex
A duplex communication system is a Point-to-point (telecommunications), point-to-point system composed of two or more connected parties or devices that can communicate with one another in both directions. Duplex systems are employed in many commu ...
, and with the ''two-wire''
I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
and
1-Wire serial buses.
Typical
applications
Application may refer to:
Mathematics and computing
* Application software, computer software designed to help the user to perform specific tasks
** Application layer, an abstraction layer that specifies protocols and interface methods used in a ...
include interfacing
microcontrollers
A microcontroller (MC, uC, or μC) or microcontroller unit (MCU) is a small computer on a single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals. Pro ...
with peripheral chips for
Secure Digital
Secure Digital (SD) is a proprietary, non-volatile, flash memory card format developed by the SD Association (SDA). Owing to their compact size, SD cards have been widely adopted in a variety of portable consumer electronics, including digi ...
cards,
liquid crystal display
A liquid-crystal display (LCD) is a flat-panel display or other Electro-optic modulator, electronically modulated optical device that uses the light-modulating properties of liquid crystals combined with polarizers to display information. Liq ...
s,
analog-to-digital and
digital-to-analog converters,
flash and
EEPROM
EEPROM or E2PROM (electrically erasable programmable read-only memory) is a type of non-volatile memory. It is used in computers, usually integrated in microcontrollers such as smart cards and remote keyless systems, or as a separate chip d ...
memory, and various communication chips.
Although SPI is a synchronous serial interface, it is different from
Synchronous Serial Interface (SSI). SSI employs
differential signaling
Differential signalling is a method for electrically transmitting information using two complementary signals. The technique sends the same electrical signal as a differential pair of signals, each in its own conductor. The pair of conduc ...
and provides only a single
simplex communication
A duplex communication system is a Point-to-point (telecommunications), point-to-point system composed of two or more connected parties or devices that can communicate with one another in both directions. Duplex systems are employed in many commu ...
channel.
Operation

Commonly, SPI has four logic signals.
Variations may use different
names
A name is a term used for identification by an external observer. They can identify a class or category of things, or a single thing, either uniquely, or within a given context. The entity identified by a name is called its referent. A person ...
or have different signals.
:
MOSI on a master outputs to MOSI on a slave. MISO on a slave outputs to MISO on a master.
Each device internally uses a
shift register
A shift register is a type of digital circuit using a cascade of flip-flop (electronics), flip-flops where the output of one flip-flop is connected to the input of the next. They share a single clock signal, which causes the data stored in the syst ...
for serial communication, which together forms an inter-chip
circular buffer
In computer science, a circular buffer, circular queue, cyclic buffer or ring buffer is a data structure that uses a single, fixed-size buffer as if it were connected end-to-end. This structure lends itself easily to buffering data streams. The ...
.
Slave devices should use
tri-state output Tri-state may refer to:
*Tri-State Airport, a public airport located in West Virginia, United States
*Tri-state area, an area where three states of the U.S. meet at one point or share a metropolitan area
*Tri-State (basketball), the 3-on-3 basketba ...
s so their MISO signal becomes
high impedance
In electronics, high impedance means that a point in a circuit (a node) allows a relatively small amount of current through, per unit of applied voltage at that point. High impedance circuits are low current and potentially high voltage, whereas ...
(electrically disconnected) when the device is not selected. Slaves without tri-state outputs cannot share a MISO line with other slaves without using an external tri-state buffer.
Data transmission

To begin communication, the SPI master first selects a slave device by pulling its low. (The bar above indicates it is an
active low signal, so a low voltage means "selected", while a high voltage means "not selected")
If a waiting period is required, such as for an analog-to-digital conversion, the master must wait for at least that period of time before issuing clock cycles.
During each SPI clock cycle, full-duplex transmission of a single bit occurs. The master sends a bit on the MOSI line while the slave sends a bit on the MISO line, and then each reads their corresponding incoming bit. This sequence is maintained even when only one-directional data transfer is intended.
Transmission using a single slave involves one shift register in the master and one shift register in the slave, both of some given word size (e.g. 8 bits). The transmissions often consist of eight-bit words, but other word-sizes are also common, for example, sixteen-bit words for touch-screen controllers or audio codecs, such as the TSC2101 by Texas Instruments, or twelve-bit words for many digital-to-analog or analog-to-digital converters.
Data is usually shifted out with the
most-significant bit (MSB) first but the original specification has a LSBFE ("LSB-First Enable") to control whether data is transferred least (LSB) or most significant bit (MSB) first. On the clock edge, both master and slave shift out a bit to its counterpart. On the next clock edge, each receiver samples the transmitted bit and stores it in the shift register as the new least-significant bit. After all bits have been shifted out and in, the master and slave have exchanged register values. If more data needs to be exchanged, the shift registers are reloaded and the process repeats. Transmission may continue for any number of clock cycles. When complete, the master stops toggling the clock signal, and typically deselects the slave.
If a single slave device is used, its pin ''may'' be fixed to
logic low if the slave permits it. With multiple slave devices, a
multidrop configuration requires an independent signal from the master for each slave device, while a
daisy-chain configuration only requires one signal.
Every slave on the bus that has not been selected should disregard the input clock and MOSI signals. And to prevent
contention on MISO, non-selected slaves must use
tristate output. Slaves that are not already tristate will need external tristate buffers to ensure this.
Clock polarity and phase
In addition to setting the clock frequency, the master must also configure the clock polarity and phase with respect to the data. Motorola
named these two options as CPOL and CPHA (for clock polarity and clock phase) respectively, a convention most vendors have also adopted.

The SPI
timing diagram shown is further described below:
* CPOL represents the polarity of the clock. Polarities can be converted with a simple
inverter.
** SCLK is a clock which idles at the
logical low voltage.
** SCLK is a clock which idles at the logical high voltage.
* CPHA represents the
phase of each data bit's transmission cycle relative to SCLK.
** For CPHA=0:
*** The first data bit is output ''immediately'' when activates.
*** Subsequent bits are output when SCLK transitions ''to'' its idle voltage level.
*** Sampling occurs when SCLK transitions ''from'' its idle voltage level.
** For CPHA=1:
*** The first data bit is output on SCLK's first clock edge ''after'' activates.
*** Subsequent bits are output when SCLK transitions ''from'' its idle voltage level.
*** Sampling occurs when SCLK transitions ''to'' its idle voltage level.
** Conversion between these two phases is non-trivial.
** MOSI and MISO signals are usually stable (at their reception points) for the half cycle until the next bit's transmission cycle starts, so SPI master and slave devices may sample data at different points in that half cycle, for flexibility, despite the original specification.
Mode numbers
The combinations of polarity and phases are referred to by these "SPI mode" numbers with CPOL as the high order bit and CPHA as the low order bit:
Notes:
* Another commonly used notation represents the mode as a (CPOL, CPHA) tuple; e.g., the value '(0, 1)' would indicate CPOL=0 and CPHA=1.
* In Full Duplex operation, the master device could transmit and receive with different modes. For instance, it could transmit in Mode 0 and be receiving in Mode 1 at the same time.
* Different vendors may use different naming schemes, like CKE for clock edge or NCPHA for the inversion of CPHA.
Valid communications
Some slave devices are designed to ignore any SPI communications in which the number of clock pulses is greater than specified. Others do not care, ignoring extra inputs and continuing to shift the same output bit. It is common for different devices to use SPI communications with different lengths, as, for example, when SPI is used to access an IC's
scan chain by issuing a command word of one size (perhaps 32 bits) and then getting a response of a different size (perhaps 153 bits, one for each pin in that scan chain).
Interrupts
Interrupts are outside the scope of SPI; their usage is neither forbidden nor specified, and so may be implemented optionally.
From master to slave
Microcontrollers configured as slave devices may have hardware support for generating interrupt signals to themselves when data words are received or overflow occurs in a receive
FIFO buffer, and may also set up an interrupt routine when their slave select input line is pulled low or high.
From slave to master
SPI slaves sometimes use an
out-of-band signal (another wire) to send an interrupt signal to a master. Examples include pen-down interrupts from
touchscreen
A touchscreen (or touch screen) is a type of electronic visual display, display that can detect touch input from a user. It consists of both an input device (a touch panel) and an output device (a visual display). The touch panel is typically l ...
sensors, thermal limit alerts from
temperature sensors, alarms issued by
real-time clock chips,
SDIO and
audio jack insertions for an
audio codec. Interrupts to master may also be faked by using
polling (similarly to
USB 1.1
Universal Serial Bus (USB) is an industry standard, developed by USB Implementers Forum (USB-IF), for digital data transmission and power delivery between many types of electronics. It specifies the architecture, in particular the physical ...
and
2.0).
Software design
SPI lends itself to a "bus driver" software design. Software for attached devices is written to call a "bus driver" that handles the actual low-level SPI hardware. This permits the driver code for attached devices to port easily to other hardware or a
bit-banging software implementation.
Bit-banging the protocol
The
pseudocode
In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages (like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actio ...
below outlines a software implementation ("
bit-banging") of SPI's protocol as a master with simultaneous output and input. This pseudocode is for CPHA=0 and CPOL=0, thus SCLK is pulled low before is activated and bits are inputted on SCLK's rising edge while bits are outputted on SCLK's falling edge.
* Initialize SCLK as low and as high
* Pull low to select the slave
* Loop for however many number of bytes to transfer:
** Initializewith the next output byte to transmit
** Loop 8 times:
***
Left-Shift the next output bit fromto MOSI
***
NOP for the slave's
setup time
*** Pull SCLK high
*** Left-Shift the next input bit from MISO into
*** NOP for the slave's hold time
*** Pull SCLK low
** now contains that recently-received byte and can be used as desired
* Pull high to unselect the slave
Bit-banging a slave's protocol is similar but different from above. An implementation might involve
busy waiting for to fall or triggering an
interrupt routine when falls, and then shifting in and out bits when the received SCLK changes appropriately for however long the transfer size is.
Bus topologies
Though the previous operation section focused on a basic interface with a single slave, SPI can instead communicate with multiple slaves using multidrop, daisy chain, or expander configurations.
Multidrop configuration

In the
multidrop bus configuration, each slave has its own , and the master selects only one at a time. MISO, SCLK, and MOSI are each shared by all devices. This is the way SPI is normally used.
Since the MISO pins of the slaves are connected together, they are required to be tri-state pins (high, low or high-impedance), where the high-impedance output must be applied when the slave is not selected. Slave devices not supporting tri-state may be used in multidrop configuration by adding a tri-state buffer chip controlled by its signal.
[Better SPI Bus Design in 3 Steps](_blank)
/ref> (Since only a single signal line needs to be tristated per slave, one typical standard logic chip that contains four tristate buffers with independent gate inputs can be used to interface up to four slave devices to an SPI bus)Caveat: All signals should start high (to indicate no slaves are selected) before sending initialization messages to any slave, so other uninitialized slaves ignore messages not addressed to them. This is a concern if the master uses general-purpose input/output (GPIO) pins (which may default to an undefined state) for and if the master uses separate software libraries to initialize each device. One solution is to configure all GPIOs used for to output a high voltage for ''all'' slaves ''before'' running initialization code from any of those software libraries. Another solution is to add a pull-up resistor
In electronic logic circuits, a pull-up resistor (PU) or pull-down resistor (PD) is a resistor used to ensure a known state for a signal. More specifically, a pull-up resistor or pull-down resistor ensures that a wire will have a high logic lev ...
on each , to ensure that all signals are initially high.
Daisy chain configuration
Some products that implement SPI may be connected in a daisy chain configuration, where the first slave's output is connected to the second slave's input, and so on with subsequent slaves, until the final slave, whose output is connected back to the master's input. This effectively merges the individual communication shift registers of each slave to form a single larger combined shift register
A shift register is a type of digital circuit using a cascade of flip-flop (electronics), flip-flops where the output of one flip-flop is connected to the input of the next. They share a single clock signal, which causes the data stored in the syst ...
that shifts data through the chain. This configuration only requires a single line from the master, rather than a separate line for each slave.
In addition to using SPI-specific slaves, daisy-chained SPI can include discrete
Discrete may refer to:
*Discrete particle or quantum in physics, for example in quantum theory
* Discrete device, an electronic component with just one circuit element, either passive or active, other than an integrated circuit
* Discrete group, ...
shift registers for more pins of inputs (e.g. using the parallel-in serial-out 74xx165) or outputs (e.g. using the serial-in parallel-out 74xx595) chained indefinitely. Other applications that can potentially interoperate with daisy-chained SPI include SGPIO, JTAG, and I2C.
Expander configurations
Expander configurations use SPI-controlled addressing units (e.g. binary decoders, demultiplexers, or shift registers) to add chip selects.
For example, one can be used for transmitting to a SPI-controlled demultiplexer an index number controlling its select signals, while another is routed through that demultiplexer according to that index to select the desired slave.
Pros and cons
Advantages
* Full duplex communication in the default version of this protocol
* Push-pull drivers (as opposed to open drain) provide relatively good signal integrity and high speed
* Higher throughput
Network throughput (or just throughput, when in context) refers to the rate of message delivery over a communication channel in a communication network, such as Ethernet or packet radio. The data that these messages contain may be delivered ov ...
than I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
or SMBus
** SPI's protocol has no maximum clock speed, however:
*** Individual devices specify acceptable clock frequencies
*** Wiring and electronics limit frequency
* Complete protocol flexibility for the bits transferred
** Not limited to 8-bit symbols
** Arbitrary choice of message size, content, and purpose
* Simple hardware and interfacing
** Hardware implementation for slaves only requires a selectable shift register
*** Slaves use the master's clock and hence do not need precision oscillators
*** Slaves do not need a unique address
An address is a collection of information, presented in a mostly fixed format, used to give the location of a building, apartment, or other structure or a plot of land, generally using border, political boundaries and street names as references, ...
unlike I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
or GPIB or SCSI
Small Computer System Interface (SCSI, ) is a set of standards for physically connecting and transferring data between computers and peripheral devices, best known for its use with storage devices such as hard disk drives. SCSI was introduced ...
*** Masters only additionally require generation of clock and signals
*** Results in simple bit-banged software implementation
** Uses only four pins on IC packages, and wires in board layouts or connectors, much fewer than parallel interfaces
*** At most one unique signal per device (); all others are shared
**** The daisy-chain configuration does not need more than one shared
** Typically lower power requirements than I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
or SMBus due to less circuitry (including pull up resistors)
** Single master means no bus arbitration (and associated failure modes) - unlike CAN-bus
** Transceivers are not needed - unlike CAN-bus
** Signals are unidirectional, allowing for easy galvanic isolation
Disadvantages
* Requires more pins on IC packages than I²C
I2C (Inter-Integrated Circuit; pronounced as "" or ""), alternatively known as I2C and IIC, is a synchronous, multi-master/multi-slave, single-ended, serial communication bus invented in 1980 by Philips Semiconductors (now NXP Semiconduct ...
, even in three-wire variants
* Only handles short distances compared to RS-232
In telecommunications, RS-232 or Recommended Standard 232 is a standard introduced in 1960 for serial communication transmission of data. It formally defines signals connecting between a ''DTE'' (''data terminal equipment'') such as a compu ...
, RS-485
RS-485, also known as TIA-485(-A) or EIA-485, is a standard, originally introduced in 1983, defining the electrical characteristics of drivers and receivers for use in serial communications systems. Electrical signaling is balanced, and Telecomm ...
, or CAN-bus (though distance can be extended with the use of transceivers like RS-422)
* Extensibility severely reduced when multiple slaves using different SPI Modes are required
** Access is slowed down when master frequently needs to reinitialize in different modes
* No formal standard
** So validating conformance is not possible
** Many existing variations complicate support
* No built-in protocol support for some conveniences:
** No hardware flow control by the slave (but the master can delay the next clock edge to slow the transfer rate)
** No hardware slave acknowledgment (the master could be transmitting to nowhere and not know it)
** No error-checking protocol
** No hot swapping
Hot swapping is the replacement or addition of components to a computer system without stopping, shutting down, or rebooting the system. Hot plugging describes only the addition of components to a running computer system. Components which ha ...
(dynamically adding nodes)
** Interrupts are outside the scope of SPI (see )
Applications
SPI is used to talk to a variety of peripherals, such as
* Sensors: temperature
Temperature is a physical quantity that quantitatively expresses the attribute of hotness or coldness. Temperature is measurement, measured with a thermometer. It reflects the average kinetic energy of the vibrating and colliding atoms making ...
, pressure
Pressure (symbol: ''p'' or ''P'') is the force applied perpendicular to the surface of an object per unit area over which that force is distributed. Gauge pressure (also spelled ''gage'' pressure)The preferred spelling varies by country and eve ...
, ADC, touchscreens
A touchscreen (or touch screen) is a type of electronic visual display, display that can detect touch input from a user. It consists of both an input device (a touch panel) and an output device (a visual display). The touch panel is typically l ...
, video game controllers
* Control devices: audio codecs, digital potentiometers, DACs
* Camera lenses: Canon EF lens mount
The EF lens mount is the standard lens mount on the Canon EOS family of SLR film and digital cameras. EF stands for "Electro-Focus": automatic focusing on EF lenses is handled by a dedicated electric motor built into the lens. Mechanically, it i ...
* Memory: flash and EEPROMs
* Real-time clocks
* LCDs, sometimes even for managing image data
* Any MMC or SD card (including SDIO variant)
* Shift registers for additional I/O
Board real estate and wiring savings compared to a parallel bus are significant, and have earned SPI a solid role in embedded systems. That is true for most system-on-a-chip
A system on a chip (SoC) is an integrated circuit that combines most or all key components of a computer or electronic system onto a single microchip. Typically, an SoC includes a central processing unit (CPU) with memory, input/output, and dat ...
processors, both with higher-end 32-bit processors such as those using ARM, MIPS, or PowerPC
PowerPC (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
and with lower-end microcontrollers such as the AVR, PIC, and MSP430. These chips usually include SPI controllers capable of running in either master or slave mode. In-system programmable AVR controllers (including blank ones) can be programmed using SPI.
Chip or FPGA
A field-programmable gate array (FPGA) is a type of configurable integrated circuit that can be repeatedly programmed after manufacturing. FPGAs are a subset of logic devices referred to as programmable logic devices (PLDs). They consist of a ...
based designs sometimes use SPI to communicate between internal components; on-chip real estate can be as costly as its on-board cousin. And for high-performance systems, FPGA
A field-programmable gate array (FPGA) is a type of configurable integrated circuit that can be repeatedly programmed after manufacturing. FPGAs are a subset of logic devices referred to as programmable logic devices (PLDs). They consist of a ...
s sometimes use SPI to interface as a slave to a host, as a master to sensors, or for flash memory used to bootstrap if they are SRAM-based.
The full-duplex capability makes SPI very simple and efficient for single master/single slave applications. Some devices use the full-duplex mode to implement an efficient, swift data stream for applications such as digital audio
Digital audio is a representation of sound recorded in, or converted into, digital signal (signal processing), digital form. In digital audio, the sound wave of the audio signal is typically encoded as numerical sampling (signal processing), ...
, digital signal processing
Digital signal processing (DSP) is the use of digital processing, such as by computers or more specialized digital signal processors, to perform a wide variety of signal processing operations. The digital signals processed in this manner are a ...
, or telecommunications channels, but most off-the-shelf chips stick to half-duplex request/response protocols.
Variations
SPI implementations have a wide variety of protocol variations. Some devices are transmit-only; others are receive-only. Slave selects are sometimes active-high rather than active-low. Some devices send the least-significant bit first. Signal levels depend entirely on the chips involved. And while the baseline SPI protocol has no command codes, every device may define its own protocol of command codes. Some variations are minor or informal, while others have an official defining document and may be considered to be separate but related protocols.
Original definition
Motorola
Motorola, Inc. () was an American multinational telecommunications company based in Schaumburg, Illinois. It was founded by brothers Paul and Joseph Galvin in 1928 and had been named Motorola since 1947. Many of Motorola's products had been ...
in 1983 listed three 6805 8-bit microcomputers that have an integrated "Serial Peripheral Interface", whose functionality is described in a 1984 manual.
AN991
Motorola's 1987 Application Node AN991 "Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers" (now under NXP, last revised 2002) informally serves as the "official" defining document for SPI.
Timing variations
Some devices have timing variations from Motorola's CPOL/CPHA modes. Sending data from slave to master may use the opposite clock edge as master to slave. Devices often require extra clock idle time before the first clock or after the last one, or between a command and its response.
Some devices have two clocks, one to read data, and another to transmit it into the device. Many of the read clocks run from the slave select line.
Transmission size
Different transmission word sizes are common. Many SPI chips only support messages that are multiples of 8 bits. Such chips can not interoperate with the JTAG or SGPIO protocols, or any other protocol that requires messages that are not multiples of 8 bits.
No slave select
Some devices do not use slave select, and instead manage protocol state machine entry/exit using other methods.
Connectors
Anyone needing an external connector for SPI defines their own or uses another standard connection such as: UEXT, Pmod, various JTAG connectors, Secure Digital
Secure Digital (SD) is a proprietary, non-volatile, flash memory card format developed by the SD Association (SDA). Owing to their compact size, SD cards have been widely adopted in a variety of portable consumer electronics, including digi ...
card socket, etc.
Flow control
Some devices require an additional flow control signal from slave to master, indicating when data is ready. This leads to a 5-wire protocol instead of the usual 4. Such a ''ready'' or ''enable'' signal is often active-low, and needs to be enabled at key points such as after commands or between words. Without such a signal, data transfer rates may need to be slowed down significantly, or protocols may need to have dummy bytes inserted, to accommodate the worst case for the slave response time. Examples include initiating an ADC conversion, addressing the right page of flash memory, and processing enough of a command that device firmware can load the first word of the response. (Many SPI masters do not support that signal directly, and instead rely on fixed delays.)
SafeSPI
SafeSPI is an industry standard for SPI in automotive applications. Its main focus is the transmission of sensor data between different devices.
High reliability modifications
In electrically noisy environments, since SPI has few signals, it can be economical to reduce the effects of common mode noise by adapting SPI to use low-voltage differential signaling. Another advantage is that the controlled devices can be designed to loop-back to test signal integrity.
Intelligent SPI controllers
A Queued Serial Peripheral Interface (QSPI; different to but has same abbreviation as ''Quad SPI'' described in ) is a type of SPI controller that uses a data queue to transfer data across an SPI bus. It has a wrap-around mode allowing continuous transfers to and from the queue with only intermittent attention from the CPU. Consequently, the peripherals appear to the CPU as memory-mapped parallel devices. This feature is useful in applications such as control of an A/D converter. Other programmable features in Queued SPI are chip selects and transfer length/delay.
SPI controllers from different vendors support different feature sets; such direct memory access
Direct memory access (DMA) is a feature of computer systems that allows certain hardware subsystems to access main system computer memory, memory independently of the central processing unit (CPU).
Without DMA, when the CPU is using programmed i ...
(DMA) queues are not uncommon, although they may be associated with separate DMA engines rather than the SPI controller itself, such as used by Multichannel Buffered Serial Port (MCBSP). Most SPI master controllers integrate support for up to four slave selects, although some require slave selects to be managed separately through GPIO lines.
Note that ''Queued SPI'' is different from ''Quad SPI'', and some processors even confusingly allow a single "QSPI" interface to operate in either quad or queued mode!
Microwire
Microwire, often spelled μWire, is essentially a predecessor of SPI and a trademark of National Semiconductor
National Semiconductor Corporation was an United States of America, American Semiconductor manufacturing, semiconductor manufacturer, which specialized in analogue electronics, analog devices and subsystems, formerly headquartered in Santa Clara, ...
. It's a strict subset of SPI: half-duplex, and using SPI mode 0. Microwire chips tend to need slower clock rates than newer SPI versions; perhaps 2 MHz vs. 20 MHz. Some Microwire chips also support a three-wire mode.
Microwire/Plus
Microwire/Plus is an enhancement of Microwire and features full-duplex communication and support for SPI modes 0 and 1. There was no specified improvement in serial clock speed.
Three-wire
Three-wire variants of SPI restricted to a half-duplex
A duplex communication system is a point-to-point system composed of two or more connected parties or devices that can communicate with one another in both directions. Duplex systems are employed in many communications networks, either to allow ...
mode use a single bidirectional data line called SISO (slave out/slave in) or MOMI (master out/master in) instead of SPI's two unidirectional lines (MOSI and MISO). Three-wire tends to be used for lower-performance parts, such as small EEPROMs used only during system startup, certain sensors, and Microwire. Few SPI controllers support this mode, although it can be easily bit-banged in software.
Dual SPI
For instances where the full-duplex nature of SPI is not used, an extension uses both data pins in a half-duplex configuration to send two bits per clock cycle. Typically a command byte is sent requesting a response in dual mode, after which the MOSI line becomes SIO0 (serial I/O 0) and carries even bits, while the MISO line becomes SIO1 and carries odd bits. Data is still transmitted most-significant bit first, but SIO1 carries bits 7, 5, 3 and 1 of each byte, while SIO0 carries bits 6, 4, 2 and 0.
This is particularly popular among SPI ROMs, which have to send a large amount of data, and comes in two variants:
* Dual read sends the command and address from the master in single mode, and returns the data in dual mode.
* Dual I/O sends the command in single mode, then sends the address and return data in dual mode.
Quad SPI
Quad SPI (QSPI; different to but has same abbreviation as ''Queued-SPI'' described in ) goes beyond dual SPI, adding two more I/O lines (SIO2 and SIO3) and sends 4 data bits per clock cycle. Again, it is requested by special commands, which enable quad mode after the command itself is sent in single mode.
; SQI Type 1: Commands sent on single line but addresses and data sent on four lines
; SQI Type 2: Commands and addresses sent on a single line but data sent/received on four lines
QPI/SQI
Further extending quad SPI, some devices support a "quad everything" mode where ''all'' communication takes place over 4 data lines, including commands. This is variously called "QPI" (not to be confused with Intel QuickPath Interconnect) or "serial quad I/O" (SQI)
This requires programming a configuration bit in the device and requires care after reset to establish communication.
Double data rate
In addition to using multiple lines for I/O, some devices increase the transfer rate by using double data rate
In computing, double data rate (DDR) describes a computer bus that transfers data on both the rising and falling edges of the clock signal and hence doubles the memory bandwidth by transferring data twice per clock cycle. This is also known a ...
transmission.
JTAG
Although there are some similarities between SPI and the JTAG (IEEE 1149.1-2013) protocol, they are not interchangeable. JTAG is specifically intended to provide reliable test access to the I/O pins from an off-board controller with less precise signal delay and skew parameters, while SPI has many varied applications. While not strictly a level sensitive interface, the JTAG protocol supports the recovery of both setup and hold violations between JTAG devices by reducing the clock rate or changing the clock's duty cycles. Consequently, the JTAG interface is not intended to support extremely high data rates.
SGPIO
SGPIO is essentially another (incompatible) application stack for SPI designed for particular backplane management activities. SGPIO uses 3-bit messages.
Intel's Enhanced Serial Peripheral Interface
Intel
Intel Corporation is an American multinational corporation and technology company headquartered in Santa Clara, California, and Delaware General Corporation Law, incorporated in Delaware. Intel designs, manufactures, and sells computer compo ...
has developed a successor to its Low Pin Count (LPC) bus that it calls the Enhanced Serial Peripheral Interface (eSPI) bus. Intel aims to reduce the number of pins required on motherboards and increase throughput compared to LPC, reduce the working voltage to 1.8 volts to facilitate smaller chip manufacturing processes, allow eSPI peripherals to share SPI flash devices with the host (the LPC bus did not allow firmware hubs to be used by LPC peripherals), tunnel previous out-of-band pins through eSPI, and allow system designers to trade off cost and performance.
An eSPI bus can either be shared with SPI devices to save pins or be separate from an SPI bus to allow more performance, especially when eSPI devices need to use SPI flash devices.
This standard defines an Alert# signal that is used by an eSPI slave to request service from the master. In a performance-oriented design or a design with only one eSPI slave, each eSPI slave will have its Alert# pin connected to an Alert# pin on the eSPI master that is dedicated to each slave, allowing the eSPI master to grant low-latency service, because the eSPI master will know which eSPI slave needs service and will not need to poll all of the slaves to determine which device needs service. In a budget design with more than one eSPI slave, all of the Alert# pins of the slaves are connected to one Alert# pin on the eSPI master in a wired-OR connection, which requires the master to poll all the slaves to determine which ones need service when the Alert# signal is pulled low by one or more peripherals that need service. Only after all of the devices are serviced will the Alert# signal be pulled high due to none of the eSPI slaves needing service and therefore pulling the Alert# signal low.
This standard allows designers to use 1-bit, 2-bit, or 4-bit communications at speeds from 20 to 66 MHz to further allow designers to trade off performance and cost.
Communications that were out-of-band of LPC like general-purpose input/output (GPIO) and System Management Bus (SMBus) should be tunneled through eSPI via virtual wire cycles and out-of-band message cycles respectively in order to remove those pins from motherboard designs using eSPI.
This standard supports standard memory cycles with lengths of 1 byte to 4 kilobytes of data, short memory cycles with lengths of 1, 2, or 4 bytes that have much less overhead compared to standard memory cycles, and I/O cycles with lengths of 1, 2, or 4 bytes of data which are low overhead as well. This significantly reduces overhead compared to the LPC bus, where all cycles except for the 128-byte firmware hub read cycle spends more than one-half of all of the bus's throughput and time in overhead. The standard memory cycle allows a length of anywhere from 1 byte to 4 kilobytes in order to allow its larger overhead to be amortised over a large transaction. eSPI slaves are allowed to initiate bus master versions of all of the memory cycles. Bus master I/O cycles, which were introduced by the LPC bus specification, and ISA-style DMA including the 32-bit variant introduced by the LPC bus specification, are not present in eSPI. Therefore, bus master memory cycles are the only allowed DMA in this standard.
eSPI slaves are allowed to use the eSPI master as a proxy to perform flash operations on a standard SPI flash memory slave on behalf of the requesting eSPI slave.
64-bit memory addressing is also added, but is only permitted when there is no equivalent 32-bit address.
The Intel Z170 chipset can be configured to implement either this bus or a variant of the LPC bus that is missing its ISA-style DMA capability and is underclocked to 24 MHz instead of the standard 33 MHz.
The eSPI bus is also adopted by AMD Ryzen chipsets.
Development tools
Single-board computers
Single-board computers may provide pin access to SPI hardware units. For instance, the Raspberry Pi's J8 header exposes at least two SPI units that can be used via Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
drivers or python.
USB to SPI adapters
There are a number of USB
Universal Serial Bus (USB) is an industry standard, developed by USB Implementers Forum (USB-IF), for digital data transmission and power delivery between many types of electronics. It specifies the architecture, in particular the physical ...
adapters that allow a desktop PC or smartphone
A smartphone is a mobile phone with advanced computing capabilities. It typically has a touchscreen interface, allowing users to access a wide range of applications and services, such as web browsing, email, and social media, as well as multi ...
with USB
Universal Serial Bus (USB) is an industry standard, developed by USB Implementers Forum (USB-IF), for digital data transmission and power delivery between many types of electronics. It specifies the architecture, in particular the physical ...
to communicate with SPI chips (e.g. CH341A/B based or FT221xs). They are used for embedded systems, chips (FPGA
A field-programmable gate array (FPGA) is a type of configurable integrated circuit that can be repeatedly programmed after manufacturing. FPGAs are a subset of logic devices referred to as programmable logic devices (PLDs). They consist of a ...
, ASIC
An application-specific integrated circuit (ASIC ) is an integrated circuit (IC) chip customized for a particular use, rather than intended for general-purpose use, such as a chip designed to run in a digital voice recorder or a high-efficien ...
, and SoC) and peripheral testing, programming and debugging. Many of them also provide scripting or programming capabilities (e.g. Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to:
* Visual Basic (.NET), the current version of Visual Basic launched in 2002 which runs on .NET
* Visual Basic (classic), the original Visual Basic suppo ...
, C/ C++, VHDL
VHDL (Very High Speed Integrated Circuit Program, VHSIC Hardware Description Language) is a hardware description language that can model the behavior and structure of Digital electronics, digital systems at multiple levels of abstraction, ran ...
) and can be used with open source programs like flashrom, IMSProg, SNANDer or avrdude for flash, EEPROM
EEPROM or E2PROM (electrically erasable programmable read-only memory) is a type of non-volatile memory. It is used in computers, usually integrated in microcontrollers such as smart cards and remote keyless systems, or as a separate chip d ...
, bootloader and BIOS
In computing, BIOS (, ; Basic Input/Output System, also known as the System BIOS, ROM BIOS, BIOS ROM or PC BIOS) is a type of firmware used to provide runtime services for operating systems and programs and to perform hardware initialization d ...
programming.
The key SPI parameters are: the maximum supported frequency for the serial interface, command-to-command latency, and the maximum length for SPI commands. It is possible to find SPI adapters on the market today that support up to 100 MHz serial interfaces, with virtually unlimited access length.
SPI protocol being a de facto standard, some SPI host adapters also have the ability of supporting other protocols beyond the traditional 4-wire SPI (for example, support of quad-SPI protocol or other custom serial protocol that derive from SPI).
Protocol analyzers
Logic analyzers are tools which collect, timestamp
A timestamp is a sequence of characters or encoded information identifying when a certain event occurred, usually giving date and time of day, sometimes accurate to a small fraction of a second. Timestamps do not have to be based on some absolu ...
, analyze, decode, store, and view the high-speed waveforms, to help debug
In engineering, debugging is the process of finding the root cause, workarounds, and possible fixes for bugs.
For software, debugging tactics can involve interactive debugging, control flow analysis, log file analysis, monitoring at the ap ...
and develop. Most logic analyzers have the capability to decode SPI bus signals into high-level protocol data with human-readable labels.
Oscilloscopes
SPI waveforms
In electronics, acoustics, and related fields, the waveform of a signal is the shape of its graph as a function of time, independent of its time and magnitude scales and of any displacement in time.David Crecraft, David Gorham, ''Electroni ...
can be seen on analog channels (and/or via digital
Digital usually refers to something using discrete digits, often binary digits.
Businesses
*Digital bank, a form of financial institution
*Digital Equipment Corporation (DEC) or Digital, a computer company
*Digital Research (DR or DRI), a software ...
channels in mixed-signal oscilloscopes). Most oscilloscope
An oscilloscope (formerly known as an oscillograph, informally scope or O-scope) is a type of electronic test instrument that graphically displays varying voltages of one or more signals as a function of time. Their main purpose is capturing i ...
vendors offer optional support for SPI protocol analysis (both 2-, 3-, and 4-wire SPI) with triggering.
Alternative terminology
Various alternative abbreviations for the four common SPI signals are used. (This section omits overbars indicating active-low.)
* Serial clock
** SCK, SCLK, CLK, SCL
* Master Out Slave In (MOSI)
** SIMO, MTSR, SPID - correspond to MOSI on both master and slave devices, connects to each other
** SDI, DI, DIN, SI, SDA - on slave devices; various abbreviations for ''serial data in''; connects to MOSI on master
** SDO, DO, DOUT, SO - on master devices; various abbreviations for ''serial data out''; connects to MOSI on slave
** COPI, PICO for ''peripheral'' and ''controller'',[SPI; OSHWA.](_blank)
/ref> or COTI for ''controller'' and ''target''
* Master In Slave Out (MISO)
** SOMI, MRST, SPIQ - correspond to MISO on both master and slave devices, connects to each other
** SDO, DO, DOUT, SO - on slave devices; connects to MISO on master
** SDI, DI, DIN, SI - on master devices; connects to MISO on slave
** CIPO, POCI, or CITO
* Slave Select (SS)
** Chip select (CS)
** CE (chip enable)
** Historical: SSEL, NSS, /SS, SS#
Microchip uses ''host'' and ''client'' though keeps the abbreviation MOSI and MISO.
See also
* List of network buses
Notes
References
External links
Intel eSPI (Enhanced Serial Peripheral Interface)
{{Computer bus
Interfaces
Computer buses
Computer hardware standards
Serial buses