Serial Peripheral Interface: Difference between revisions
smells like advertising |
|||
Line 1: | Line 1: | ||
{{Short description|Synchronous serial communication interface}} |
|||
{| align="right" |
|||
{{Cleanup rewrite|[[WP:NOTTEXTBOOK|it reads like a guide or textbook]]|article|date=March 2021}} |
|||
|- |
|||
{{recentism|date=December 2023}} |
|||
| [[Image:SPI single slave.svg|thumb|right|350px|SPI bus: single master and single slave]] |
|||
{{Infobox connector <!-- NOTE: Not a perfect template match, but good enough for now --> |
|||
|} |
|||
| name = Serial Peripheral Interface (SPI) |
|||
| type = [[Serial communication]] [[Bus (computing)|bus]] |
|||
| designer = [[Motorola]] |
|||
| data_style = [[Full-duplex]] [[serial communication|serial]] |
|||
| daisy_chain = [[#Daisy chain configuration|Depends]] on devices |
|||
| manufacturer = various |
|||
| data_devices = [[#Multidrop configuration|Multidrop]] limited by chip selects. [[#Daisy chain configuration|Daisy chaining]] unlimited. |
|||
| data_bit_width = 1 bit (bidirectional) |
|||
| high_freq = yes |
|||
| pin_custom1_name = MOSI |
|||
| pin_name_custom1 = Master Out Slave In |
|||
| pin_name_custom2 = Master In Slave Out |
|||
| pin_custom2_name = MISO |
|||
| pin_custom3_name = SCLK |
|||
| pin_custom4_name = {{Overline|CS}} |
|||
| pin_name_custom3 = Serial Clock |
|||
| pin_name_custom4 = [[Chip Select]] (one or more) |
|||
| pinout_notes = (pins may have [[#Alternative terminology|alternative names]]) |
|||
| maximum_voltage = Unspecified |
|||
| maximum_current = Unspecified |
|||
| physical_connector = Unspecified |
|||
| design_date = Around early 1980s{{NoteTag|The earliest definitive mention of a "Serial Peripheral Interface" in bitsavers archives of Motorola manuals is from 1983 (see {{slink||Original definition}}). While some sources on the web allege that Motorola introduced SPI when 68000 was introduced in 1979, however many of those appear to be [[citogenesis]] or speculation, and Motorola's 1983 68000 manual has no mention of "Serial Peripheral Interface", so the alleged 1979 date doesn't seem to be reliable information. Please only add a specific design_date if you have a definitive source from Motorola around then.}} |
|||
}} |
|||
'''Serial Peripheral Interface''' ('''SPI''') is a [[de facto standard|''de facto'' standard]] (with many [[#Variations|variants]]) for [[Comparison of synchronous and asynchronous signalling|synchronous]] [[serial communication]], used primarily in [[embedded systems]] for short-distance [[wired communication]] between [[integrated circuits]]. |
|||
The '''Serial Peripheral Interface Bus''' or '''SPI''' (often pronounced "es-pē-ī" [IPA: ɛs pi aɪ] or "spy" [IPA: spaɪ]) bus is a [[synchronous]] [[Serial communications|serial data link]] standard named by [[Motorola]] that operates in [[full duplex]] mode. Devices communicate in master/slave mode where the master device initiates the [[data frame]]. Multiple slave devices are allowed with individual [[slave select]] (chip select) lines. Sometimes SPI is called a "four wire" serial bus, contrasting with [[Serial_Peripheral_Interface_Bus#3-Wire_Serial_Buses | three]], [[I2C | two]], and [[1-Wire | one wire]] serial buses. |
|||
SPI follows a [[master–slave (technology)|master–slave architecture]], <ref name=":0">{{Cite web |last=Dhaker |first=Piyu |date=2018 |title=Introduction to SPI Interface |url=https://www.analog.com/en/analog-dialogue/articles/introduction-to-spi-interface.html |url-status=live |archive-url=https://web.archive.org/web/20230525152752/https://www.analog.com/en/analog-dialogue/articles/introduction-to-spi-interface.html |archive-date=2023-05-25 |access-date=2023-07-21 |website=[[Analog Dialogue]]}}</ref> called ''main–sub'' herein, {{NoteTag|Using main and sub maintains the same initial letters to remain in sync with the line names. For example MISO could be expanded as "main in, sub out"}} {{NoteTag|The {{slink||Alternative terminology}} section gives more details on proposed alternative terminology. See [[Talk:Serial Peripheral Interface#Terminology|the talk page]] for an ongoing discussion.}} where one{{NoteTag|For any given transaction, only one device is the main. However, some devices support changing main and sub roles on the fly. Most microcontrollers can easily reconfigure their SPI's role, and some Atmel and Silabs devices can change roles depending on an external pin.}} main device [[Signaling (telecommunications)|orchestrates communication]] with one or more sub (peripheral) devices by driving the [[clock signal|clock]] and [[chip select]] signals. |
|||
== Interface == |
|||
The SPI bus specifies four logic signals. |
|||
[[Motorola]]'s original specification (from the early 1980s) uses four [[logic signal]]s, aka lines or wires, to support [[full duplex]] communication. It is sometimes called a ''four-wire'' [[serial bus]] to contrast with [[Serial Peripheral Interface#Three-wire|three-wire]] variants which are [[half duplex]], and with the ''two-wire'' [[I²C]] and [[1-Wire]] serial buses. |
|||
* SCLK — Serial Clock (output from master) |
|||
* MOSI/SIMO — Master Output, Slave Input (output from master) |
|||
* MISO/SOMI — Master Input, Slave Output (output from slave) |
|||
* SS — [[Slave Select]] ([[active low]]; output from master) |
|||
Typical [[#Applications|applications]] include interfacing [[microcontrollers]] with peripheral chips for [[Secure Digital]] cards, [[liquid crystal display]]s, [[analog-to-digital]] and [[digital-to-analog converters]], [[Flash memory#Serial flash|flash]] and [[EEPROM#Serial bus devices|EEPROM]] memory, and various communication chips. |
|||
Alternative naming conventions are also widely used: |
|||
* SCK — Serial Clock (output from master) |
|||
* SDI, DI, SI — Serial Data In |
|||
* SDO, DO, SO — Serial Data Out |
|||
* nCS, CS, nSS, STE — [[Chip Select]], Slave Transmit Enable ([[active low]]; output from master) |
|||
Although SPI is a synchronous serial interface,<ref>{{cite web |url= https://digital.ni.com/public.nsf/allkb/862567530005F09C862566BE004E469D |title= What is Serial Synchronous Interface (SSI)? |access-date= 2015-01-28 }}</ref> it is different from [[Synchronous Serial Interface]] (SSI). SSI employs [[differential signaling]] and provides only a single [[simplex communication]] channel. |
|||
The SDI/SDO (DI/DO, SI/SO) convention requires that SDO on the master be connected to SDI on the slave, and vice-versa. |
|||
:''SPI port pin names for particular IC products may differ from those depicted in these illustrations.'' |
|||
== |
==Operation== |
||
[[File:SPI basic operation, single Main & Sub.svg|thumb|368x368px|Figure 1: Common SPI connectivity with a single sub.]] |
|||
The SPI bus can operate with a single master device and with one or more slave devices. |
|||
Commonly, SPI has four logic signals. [[#Variations|Variations]] may use different [[#Alternative terminology|names]] or have different signals. Historical terms are shown in parentheses. |
|||
:{| class="wikitable" |
|||
If a single slave device is used, the SS pin ''may'' be fixed to logic low if the slave permits it. Some slaves require the [[falling edge]] (high->low transition) of the slave select to initiate an action such as the MAX1242 by [[Maxim Integrated Products|Maxim]], an [[analog-to-digital converter|ADC]], that starts conversion on said transition. With multiple slave devices, an independent SS signal is required from the master for each slave device. |
|||
! Abbr.!! Name !! Description |
|||
|- |
|||
| {{center|{{Overline|CS}}}} || {{center|chip select}} || [[Logic level#Active state|Active-low]] [[chip select]] signal from main to<br />enable communication with a specific sub device |
|||
|- |
|||
| {{center|SCLK}} || {{center|serial clock}} || [[Clock signal]] from main |
|||
|- |
|||
| {{center|MOSI}} || {{center|main{{nbsp}}out,{{nbsp}}sub{{nbsp}}in<br />{{small|(master{{nbsp}}out,{{nbsp}}slave{{nbsp}}in)}}}} || [[Serial communication|Serial data]] from main, [[most-significant bit]] first |
|||
|- |
|||
| {{center|MISO}} || {{center|main{{nbsp}}in,{{nbsp}}sub{{nbsp}}out<br />{{small|(master{{nbsp}}in,{{nbsp}}slave{{nbsp}}out)}}}} || [[Serial communication|Serial data]] from sub, most-significant bit first |
|||
|} |
|||
MOSI on a main outputs to MOSI on a sub. MISO on a sub outputs to MISO on a main. |
|||
Most devices have [[tri-state output]]s that become [[high impedance]] ("disconnected") when the device is not selected. Devices without tristate outputs can't share SPI bus segments with other devices; only one such slave may talk to the master, and only its chipselect may be activated. |
|||
Each device internally uses a [[shift register]] for serial communication, which together forms an inter-chip [[circular buffer]]. |
|||
===Data Transmission=== |
|||
[[Image:SPI 8-bit circular transfer.svg|400px|thumb|A typical hardware setup using two [[shift register]]s to form an inter-chip [[circular buffer]]]] |
|||
Sub devices should use [[tri-state output]]s so their MISO signal becomes [[high impedance]] (electrically disconnected) when the device is not selected. Subs without tri-state outputs cannot share a MISO line with other subs without using an external tri-state buffer. |
|||
To begin a communication, the master first configures the clock, using a frequency less than or equal to the maximum frequency the slave device supports. Such frequencies are commonly in the range of 1-70 MHz. |
|||
===Data transmission=== |
|||
The master then pulls the slave select low for the desired chip. |
|||
To begin communication, the SPI main first selects a sub device by pulling its {{Overline|CS}} low. (Note: the bar above {{Overline|CS}} 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 analog-to-digital conversion) then the master must wait for at least that period of time before starting to issue clock cycles. |
|||
If a waiting period is required, such as for an analog-to-digital conversion, the main must wait for at least that period of time before issuing clock cycles.{{NoteTag|Some subs require a falling edge of the {{Overline|Chip Select}} signal to initiate an action. An example is the Maxim MAX1242 ADC, which starts conversion on a high→low transition.}} |
|||
During each SPI clock cycle, a [[full duplex]] data transmission occurs: |
|||
* the master sends a bit on the MOSI line; the slave reads it from that same line |
|||
* the slave sends a bit on the MISO line; the master reads it from that same line |
|||
During each SPI clock cycle, full-duplex transmission of a single bit occurs. The main sends a bit on the MOSI line while the sub 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. |
|||
Not all transmissions require all four of these operations to be ''meaningful'' but they do happen. |
|||
Transmission using a single sub (Figure 1) involves one shift register in the main and one shift register in the sub, both of some given word size (e.g. 8 bits),{{NoteTag|Transmissions often consist of eight-bit words. However, 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.}} connected in a virtual [[ring topology]]. Data is usually shifted out with the [[most-significant bit]] (MSB) first.{{NoteTag|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 main and sub 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 main and sub 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 main stops toggling the clock signal, and typically deselects the sub. |
|||
Transmissions normally involve two shift registers of some given word size, such as eight bits, one in the master and one in the slave; they are connected in a ring. |
|||
Data is usually shifted out with the most significant bit first, while shifting a new least significant bit into the same register. |
|||
After that register has been shifted out, the master and slave have exchanged register values. |
|||
Then each device takes that value and does something with it, such as writing it to memory. |
|||
If there is more data to exchange, the shift registers are loaded with new data and the process repeats. |
|||
If a single sub device is used, its {{Overline|CS}} pin ''may'' be fixed to [[logic level|logic low]] if the sub permits it. With multiple sub devices, a [[#Multidrop configuration|multidrop configuration]] requires an independent {{Overline|CS}} signal from the main for each sub device, while a [[#Daisy chain configuration|daisy-chain configuration]] only requires one {{Overline|CS}} signal. |
|||
Transmissions may involve any number of clock cycles. When there are no more data to be transmitted, the master stops toggling its clock. Normally, it then deselects the slave. |
|||
Every sub on the bus that has not been selected should disregard the input clock and MOSI signals. And to prevent [[Bus contention|contention]] on MISO, non-selected subs must use [[Three-state logic|tristate]] output. Subs that aren't already tristate will need external tristate buffers to ensure this.<ref name="Better SPI Bus Design in 3 Steps" /> |
|||
Transmissions often consist of 8-bit words, and a master can initiate multiple such transmissions if it wishes/needs. However, other word sizes are also common, such as 16-bit words for touchscreen controllers or audio codecs, like the TSC2101 from [[Texas Instruments]]; or 12-bit words for many digital-to-analog or analog-to-digital converters. |
|||
===Clock polarity and phase=== |
|||
Every slave on the bus that hasn't been activated using its slave select line must disregard the input clock and MOSI signals, and must not drive MISO. The master selects only one slave at a time. |
|||
In addition to setting the clock frequency, the main must also configure the clock polarity and phase with respect to the data. Motorola<ref>[https://web.archive.org/web/20150413003534/http://www.ee.nmt.edu/~teare/ee308l/datasheets/S12SPIV3.pdf SPI Block Guide v3.06; Motorola/Freescale/NXP; 2003.]</ref><ref name=":4" /> named these two options as CPOL and CPHA (for '''c'''lock '''pol'''arity and '''c'''lock '''pha'''se) respectively, a convention most vendors have also adopted. |
|||
[[File:SPI timing diagram CS.svg|thumb|338x338px|SPI [[Digital timing diagram|timing diagram]] for both clock polarities and phases. Data bits output on blue lines if CPHA=0, or on red lines if CPHA=1, and sample on opposite-colored lines. Numbers identify data bits. Z indicates [[high impedance]].]] |
|||
====Clock polarity and phase==== |
|||
[[Image:SPI timing diagram.svg|thumb|400px|A timing diagram showing clock polarity and phase]] |
|||
The SPI [[digital timing diagram|timing diagram]] shown is further described below: |
|||
In addition to setting the clock frequency, the master must also configure the clock polarity and phase with respect to the data. Freescale's SPI Block Guide <ref>[http://www.freescale.com/files/microcontrollers/doc/ref_manual/S12SPIV3.pdf SPI Block Guide V03.06], [[Freescale Semiconductor]]</ref> names these two options as CPOL and CPHA respectively, and most vendors have adopted that convention. |
|||
* CPOL represents the polarity of the clock. Polarities can be converted with a simple [[inverter (logic gate)|inverter]]. |
|||
** SCLK{{Subscript|1=CPOL=0}} is a clock which idles at the [[logical low]] voltage. |
|||
** SCLK{{Subscript|1=CPOL=1}} is a clock which idles at the logical high voltage. |
|||
* CPHA represents the [[Phase (waves)|phase]] of each data bit's transmission cycle relative to SCLK. |
|||
** For CPHA=0: |
|||
*** The first data bit is output ''immediately'' when {{Overline|CS}} 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'' {{Overline|CS}} 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. |
|||
** Note: 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 main and sub devices may sample data at different points in that half cycle, for flexibility, despite the original specification. |
|||
===Mode numbers === |
|||
The [[Digital timing diagram|timing diagram]] is shown to the right. The timing is further described below and applies to both the master and the slave device. |
|||
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: |
|||
* At CPOL=0 the base value of the clock is zero |
|||
** For CPHA=0, data are read on the clock's [[rising edge]] (low->high transition) and data are changed on a [[falling edge]] (high->low clock transition). |
|||
** For CPHA=1, data are read on the clock's falling edge and data are changed on a rising edge. |
|||
* At CPOL=1 the base value of the clock is one (inversion of CPOL=0) |
|||
** For CPHA=0, data are read on clock's falling edge and data are changed on a rising edge. |
|||
** For CPHA=1, data are read on clock's rising edge and data are changed on a falling edge. |
|||
That is, CPHA=0 means sample on the leading (first) clock edge, while CPHA=1 means sample on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling. Note that with CPHA=0, the data must be stable for a half cycle before the first clock cycle. For all CPOL and CPHA modes, the initial clock value must be stable before the chip select line goes active. |
|||
This adds more flexibility to the communication channel between the master and slave. |
|||
====Mode Numbers==== |
|||
The combinations of polarity and phases are often referred to as modes which are commonly numbered according to the following convention, with CPOL as the high order bit and CPHA as the low order bit: |
|||
{| class="wikitable" |
{| class="wikitable" |
||
|- |
|- |
||
! SPI mode |
|||
! Mode |
|||
! CPOL |
! Clock polarity<br />(CPOL) |
||
! CPHA |
! Clock phase<br />(CPHA) |
||
!Data is shifted out on |
|||
! Data is sampled on |
|||
|- |
|- |
||
| 0 |
| 0 || 0 || 0 |
||
|falling SCLK, and when {{Overline|CS}} activates || rising SCLK |
|||
| 0 |
|||
| 0 |
|||
|- |
|- |
||
| 1 |
| 1 || 0 || 1 |
||
| rising SCLK || falling SCLK |
|||
| 0 |
|||
| 1 |
|||
|- |
|- |
||
| 2 |
| 2 || 1 || 0 |
||
| rising SCLK, and when {{Overline|CS}} activates || falling SCLK |
|||
| 1 |
|||
| 0 |
|||
|- |
|- |
||
| 3 |
| 3 || 1 || 1 |
||
|falling SCLK|| rising SCLK |
|||
| 1 |
|||
| 1 |
|||
|} |
|} |
||
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. |
|||
* 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. |
|||
=== Independent slave SPI configuration === |
|||
* In Full Duplex operation, the main 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. |
|||
[[Image:SPI three slaves.svg|thumb|right|350px|Typical SPI bus: master and three independent slaves]] |
|||
* Different vendors may use different naming schemes, like CKE for clock edge or NCPHA for the inversion of CPHA. |
|||
=== Valid communications === |
|||
In the independent slave configuration, there is an independent slave select line for each slave. 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. |
|||
Some sub 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=== |
|||
=== Daisy chain SPI configuration === |
|||
Interrupts are outside the scope of SPI; their usage is neither forbidden nor specified, and so may optionally be implemented. |
|||
[[Image:SPI three slaves daisy chained.svg|thumb|350px|Daisy-chained SPI bus: master and cooperative slaves]] |
|||
==== From main to sub ==== |
|||
Some products with SPI bus are designed to be capable of being connected in a [[daisy chain]] configuration, the first slave output being connected to the second slave input, etc. The SPI port of each slave is designed to send out during the second group of clock pulses an exact copy of what it received during the first group of clock pulses. The whole chain acts as an SPI communication [[shift register]]; daisy chaining is often done with shift registers to provide a bank of inputs or outputs through SPI. Such a feature only requires a single SS line from the master, rather than a separate SS line for each slave. |
|||
Microcontrollers configured as sub devices may have hardware support for generating interrupt signals to themselves when data words are received or overflow occurs in a receive [[FIFO (computing and electronics)|FIFO]] buffer,<ref>{{Cite web |date=2002 |title=TMS320x281x Serial Peripheral Interface Reference Guide |url=https://www.ti.com/lit/pdf/spru059 |website=[[Texas Instruments]] |pages=16–17}}</ref> and may also set up an interrupt routine when their chip select input line is pulled low or high. |
|||
==== From sub to main ==== |
|||
This somewhat resembles [[SGPIO]], although SGPIO is limited to particular backplane management activities and would not interoperate with most SPI chips. |
|||
SPI subs sometimes use an [[out-of-band signal]] (another wire) to send an interrupt signal to a main. Examples include pen-down interrupts from [[touchscreen]] sensors, thermal limit alerts from [[List of temperature sensors|temperature sensors]], alarms issued by [[real-time clock]] chips, [[Secure Digital#SDIO|SDIO]]{{NoteTag|Not to be confused with the SDIO (Serial Data I/O) line of the half-duplex implementation of SPI sometimes also called "3-wire" SPI. Here e.g. MOSI (via a resistor) and MISO (no resistor) of a main is connected to the SDIO line of a sub.|name=3wireSDI}} and [[audio jack]] insertions for an [[audio codec]]. Interrupts to main may also be faked by using [[Polling (computer science)|polling]] (similarly to [[USB 1.1]] and [[USB 2.0|2.0]]). |
|||
===Software design=== |
|||
=== Valid SPI communications === |
|||
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. |
|||
Some slave devices are designed to ignore any SPI communications in which the number of clock pulses is greater than specified. Others don't 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 the [[scan chain]] of a digital IC 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). |
|||
=== |
===Bit-banging the protocol=== |
||
The [[pseudocode]] below outlines a software implementation ("[[bit-banging]]") of SPI's protocol as a main with simultaneous output and input. This pseudocode is for CPHA=0 and CPOL=0, thus SCLK is pulled low before {{Overline|CS}} is activated and bits are inputted on SCLK's rising edge while bits are outputted on SCLK's falling edge. |
|||
SPI devices sometimes use another signal line to send an interrupt signal to a host CPU. Examples include pen-down interrupts from touchscreen sensors, thermal limit alerts from temperature sensors, alarms issued by real time clock chips, and headset jack insertions from the sound codec in a cell phone. |
|||
* Initialize SCLK as low and {{Overline|CS}} as high |
|||
=== Example of bit-banging the SPI protocol === |
|||
* Pull {{Overline|CS}} low to select the sub |
|||
An example of [[Bit-banging]] the SPI protocol is included below in the C programming language, with CPOL=0, CPHA=0, and eight bits per transfer. The select line should be toggled low for the peripheral before the start of the transfer, and high afterwards. Many peripherals allow or require several transfers while the select line is low. |
|||
* Loop for however many number of bytes to transfer:{{NoteTag|Peripherals may allow or require a particular number (or any number) of transfer bytes while selected, as specified in their datasheet.}} |
|||
<source lang="cpp"> |
|||
** Initialize{{Code|byte_out|C}}with the next output byte to transmit |
|||
#define SPISPEED 2 /* selects the speed of the transfer */ |
|||
** Loop 8 times: |
|||
unsigned char SPIBitBang(unsigned char outbyte) |
|||
*** [[Left-shift operator|Left-Shift]]{{NoteTag|Left-shifts are used because SPI normally transmits the most-significant bit first. Right-shifts could instead be used to transfer least-significant bit first.}} the next output bit from{{Code|byte_out|C}}to MOSI |
|||
{ |
|||
*** [[NOP (code)|NOP]] for the sub's [[setup time]] |
|||
unsigned char inbyte = 0; |
|||
*** Pull SCLK high |
|||
int bitno = 8, dly; |
|||
*** Left-Shift the next input bit from MISO into{{Code|byte_in|C}} |
|||
do { |
|||
*** NOP for the sub's hold time |
|||
if (outbyte & 0x80) SETMOSI(); |
|||
*** Pull SCLK low |
|||
else CLRMOSI(); |
|||
** {{Code|byte_in|C}}now contains that recently-received byte and can be used as desired |
|||
outbyte <<= 1; |
|||
* Pull {{Overline|CS}} high to unselect the sub |
|||
for (dly=SPISPEED;dly>0;dly--) CLRCLK(); |
|||
Bit-banging a sub's protocol is similar but different from above. An implementation might involve [[busy waiting]] for {{Overline|CS}} to fall or triggering an [[Interrupt handler|interrupt routine]] when {{Overline|CS}} falls, and then shifting in and out bits when the received SCLK changes appropriately for however long the transfer size is. |
|||
for (dly=SPISPEED;dly>0;dly--) SETCLK(); |
|||
inbyte = (inbyte<<1) | READMISO(); |
|||
for (dly=SPISPEED;dly>0;dly--) CLRCLK(); |
|||
} while ((--bitno)>0); |
|||
CLRMOSI(); |
|||
return inbyte; |
|||
} |
|||
</source> |
|||
== |
== Bus topologies == |
||
Though the previous operation section focused on a basic interface with a single sub, SPI can instead communicate with multiple subs using multidrop, daisy chain, or expander configurations. |
|||
=== Advantages === |
|||
* [[Full duplex]] communication |
|||
===Multidrop configuration=== |
|||
* Higher throughput than [[I²C]] or [[System_Management_Bus|SMBus]] |
|||
[[File:SPI main sub multidrop.svg|thumb|216x216px|Multidrop SPI bus]] |
|||
In the [[multidrop bus]] configuration, each sub has its own {{Overline|CS}}, and the main 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 subs 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 sub is not selected. Sub devices not supporting tri-state may be used in multidrop configuration by adding a tri-state buffer chip controlled by its {{Overline|CS}} signal.<ref name="Better SPI Bus Design in 3 Steps">[https://www.pjrc.com/better-spi-bus-design-in-3-steps/ Better SPI Bus Design in 3 Steps]</ref> (Since only a single signal line needs to be tristated per sub, one typical standard logic chip that contains four tristate buffers with independent gate inputs can be used to interface up to four sub devices to an SPI bus)<blockquote>Caveat: All {{Overline|CS}} signals should start high (to indicate no chips are selected) before sending initialization messages to any sub, so other uninitialized subs ignore messages not addressed to them. This is a concern if the main uses [[General-purpose input/output|general-purpose input/output (GPIO) pins]] (which may default to an undefined state) for {{Overline|CS}} and if the main uses separate software libraries to initialize each device. One solution is to configure all GPIOs used for {{Overline|CS}} to output a high voltage for ''all'' subs ''before'' running initialization code from any of those software libraries. Another solution is to add a [[pull-up resistor]] on each {{Overline|CS}}, to ensure that all {{Overline|CS}} signals are initially high.<ref name="Better SPI Bus Design in 3 Steps" /></blockquote> |
|||
===Daisy chain configuration=== |
|||
[[File:SPI main sub daisychain.svg|thumb|229x229px|Daisy-chained SPI]] |
|||
Some products that implement SPI may be connected in a [[Daisy chain (electrical engineering)|daisy chain]] configuration, where the first sub's output is connected to the second sub's input, and so on with subsequent subs, until the final sub, whose output is connected back to the main's input. This effectively merges the individual communication shift registers of each sub to form a single larger combined [[shift register]] that shifts data through the chain. This configuration only requires a single {{Overline|CS}} line from the main, rather than a separate {{Overline|CS}} line for each sub.<ref>[https://www.maximintegrated.com/en/app-notes/index.mvp/id/3947 Maxim-IC application note 3947: "Daisy-Chaining SPI Devices"]</ref> |
|||
In addition to using SPI-specific subs, daisy-chained SPI can include [[Discrete component|discrete]] shift registers for [[Shift register#More I/O pins|more pins]] of inputs (e.g. using the [[Shift register#Parallel-in serial-out (PISO)|parallel-in serial-out]] [[List of 7400-series integrated circuits|74]]<nowiki/>xx165)<ref name=":3">{{Cite web |last=Gammon |first=Nick |date=2013-03-23 |title=Gammon Forum : Electronics : Microprocessors : Using a 74HC165 input shift register |url=https://www.gammon.com.au/forum/?id=11979 |url-status=live |archive-url=https://web.archive.org/web/20230729042912/http://www.gammon.com.au/forum/?id=11979 |archive-date=2023-07-29 |access-date=2023-08-03 |website=Gammon Forum}}</ref> or outputs (e.g. using the [[Shift register#Serial-in parallel-out (SIPO)|serial-in parallel-out]] [[List of 7400-series integrated circuits|74]]<nowiki/>xx595)<ref name=":2">{{Cite web |last=Gammon |first=Nick |date=2012-01-31 |title=Gammon Forum : Electronics : Microprocessors : Using a 74HC595 output shift register as a port-expander |url=https://www.gammon.com.au/forum/?id=11518 |url-status=live |archive-url=https://web.archive.org/web/20230714101259/http://www.gammon.com.au/forum/?id=11518 |archive-date=2023-07-14 |access-date=2023-08-03 |website=Gammon Forum}}</ref> chained indefinitely. Other applications that can potentially interoperate with daisy-chained SPI include [[SGPIO]], [[JTAG]],<ref>{{citation |title= Interfaces |year = 1977|url= https://books.google.com/books?id=8od7phxJHGkC |pages= 80, 84}}</ref> and [[I2C|I<sup>2</sup>C]]. |
|||
===Expander configurations=== |
|||
Expander configurations use SPI-controlled addressing units (e.g. [[Binary decoder|binary decoders]], [[Demultiplexer|demultiplexers]], or shift registers) to add chip selects. |
|||
For example, one {{Overline|CS}} can be used for transmitting to a SPI-controlled demultiplexer an index number controlling its select signals, while another {{Overline|CS}} is routed through that demultiplexer according to that index to select the desired sub.<ref>{{cite web |date=2001-07-01 |title=Serial-Control Multiplexer Expands SPI Chip Selects |url=http://www.farnell.com/datasheets/312519.pdf |archive-url=https://web.archive.org/web/20190819062018/http://www.farnell.com/datasheets/312519.pdf |archive-date=2019-08-19 |access-date= |website=[[Premier Farnell]]}}</ref> |
|||
==Pros and cons== |
|||
===Advantages=== |
|||
* Full duplex communication in the default version of this protocol |
|||
* [[Push-pull output|Push-pull drivers]] (as opposed to [[open drain]]) provide relatively good signal integrity and high speed |
|||
* Higher [[throughput]] than [[I²C]] or [[System Management Bus|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 |
* Complete protocol flexibility for the bits transferred |
||
** Not limited to 8-bit |
** Not limited to 8-bit symbols |
||
** Arbitrary choice of message size, content, and purpose |
** Arbitrary choice of message size, content, and purpose |
||
* |
* Simple hardware and interfacing |
||
** Hardware implementation for subs only requires a selectable shift register |
|||
** Typically lower power requirements than I²C or SMBus due to less circuitry (including pullups) |
|||
*** Subs use the main's clock and hence do not need precision oscillators |
|||
** No arbitration or associated failure modes |
|||
*** Subs do not need a unique [[address space|address]]{{snd}} unlike [[I²C]] or [[GPIB]] or [[SCSI]] |
|||
** Slaves use the master's clock, and don't need precision oscillators |
|||
*** Mains only additionally require generation of clock and {{Overline|CS}} signals |
|||
** Transceivers are not needed |
|||
*** Results in simple bit-banged software implementation |
|||
* Uses many fewer pins on IC packages, and wires in board layouts or connectors, than parallel interfaces |
|||
** Uses only four pins on IC packages, and wires in board layouts or connectors, much fewer than [[Parallel communication|parallel interfaces]] |
|||
* At most one "unique" bus signal per device (chipselect); all others are shared |
|||
*** At most one unique signal per device ({{Overline|CS}}); all others are shared |
|||
**** Note: the daisy-chain configuration doesn't need more than one shared {{Overline|CS}} |
|||
** Typically lower power requirements than [[I²C]] or SMBus due to less circuitry (including pull up resistors) |
|||
** Single main 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, even in |
* Requires more pins on IC packages than [[I²C]], even in [[Serial Peripheral Interface#Three-wire|three-wire]] variants |
||
* Only handles short distances compared to [[RS-232]], [[RS-485]], or [[CAN-bus]] (though distance can be extended with the use of transceivers like [[RS-422]]) |
|||
* No in-band addressing; out-of-band [[chip select]] signals are required on shared buses |
|||
* Extensibility severely reduced when multiple subs using different SPI Modes are required |
|||
* No hardware [[flow control]] |
|||
** Access is slowed down when main frequently needs to reinitialize in different modes |
|||
* No slave acknowledgment (the master could be "talking" to nothing and not know it) |
|||
* No formal standard |
|||
* Supports only one master device |
|||
* |
** So validating conformance is not possible |
||
** Many existing variations complicate support |
|||
* Only handles short distances compared to [[RS-232]], [[RS-485]], or [[CAN-bus]] |
|||
* No built-in protocol support for some conveniences: |
|||
** No hardware [[flow control (data)|flow control]] by the sub (but the main can delay the next clock edge to slow the transfer rate) |
|||
** No hardware sub acknowledgment (the main could be transmitting to nowhere and not know it) |
|||
** No error-checking protocol |
|||
** No [[hot swapping]] (dynamically adding nodes) |
|||
** Interrupts are outside the scope of SPI (see {{Slink|2=Interrupts|nopage=y}}) |
|||
== |
==Applications== |
||
{{Multiple image |
|||
The board real estate savings compared to a parallel I/O bus are significant, and have earned SPI a solid role in embedded systems. That's true for most [[System-on-a-chip]] processors, both with higher end 32-bit processors such as those using [[ARM_architecture|ARM]] and with lower end microcontrollers such as the [[Atmel_AVR|AVR]], [[PIC_microcontroller|PIC]] and [[MSP430]]. These chips usually include SPI controllers capable of running in either master or slave mode. |
|||
| image1 = ATI Radeon X1300 256MB - Atmel 25F512AN-5397.jpg |
|||
| caption1 = SPI Memory by [[Atmel]] |
|||
| image2 = ADSV-931 Mini Docking Station - LAN module - Fairchild 93C46-93553.jpg |
|||
| caption2 = [[Fairchild Semiconductor|Fairchild]] EEPROM using [[#Microwire|Microwire]] |
|||
| image3 = Sumup AIR1 E205 - board - Microchip 26F032B-1521.jpg |
|||
| caption3 = [[Microchip Technology|Microchip]] 32-Mbit [[#QPI/SQI|SQI]] Flash Memory |
|||
| direction = horizontal |
|||
| total_width = 400 |
|||
}} |
|||
SPI is used to talk to a variety of peripherals, such as |
|||
* Sensors: [[temperature]], [[pressure]], [[analog-to-digital converter|ADC]], [[touchscreens]], [[video game controllers]] |
|||
* Control devices: [[audio codec]]s, [[digital potentiometers]], [[digital-to-analog converter|DACs]] |
|||
* Camera lenses: [[Canon EF lens mount]] |
|||
* Communications: [[Ethernet]], [[USB]], [[USART]], [[CAN bus|CAN]], [[IEEE 802.15.4]], [[IEEE 802.11]] |
|||
* Memory: [[flash memory#Serial flash|flash]] and [[EEPROM#Serial bus devices|EEPROMs]] |
|||
* [[Real-time clock|Real-time clocks]] |
|||
* [[LCD|LCDs]], sometimes even for managing image data |
|||
* Any [[MultiMediaCard|MMC]] or [[Secure Digital|SD]] card (including [[Secure Digital#SDIO|SDIO]] variant{{NoteTag|Not to be confused with the SDIO (Serial Data I/O) line of the half-duplex implementation of SPI sometimes also called "3-wire" SPI. Here e.g. MOSI (via a resistor) and MISO (no resistor) of a main is connected to the SDIO line of a sub.|name=3wireSDI}}) |
|||
* [[Shift registers]] for additional I/O<ref name=":3" /><ref name=":2" /> |
|||
[[Printed circuit board|Board]] real estate and wiring savings compared to a [[Parallel communication|parallel]] bus are significant, and have earned SPI a solid role in embedded systems. That is true for most [[system-on-a-chip]] processors, both with higher-end 32-bit processors such as those using [[ARM architecture|ARM]], [[MIPS architecture|MIPS]], or [[PowerPC]] and with lower-end microcontrollers such as the [[Atmel AVR|AVR]], [[PIC microcontroller|PIC]], and [[MSP430]]. These chips usually include SPI controllers capable of running in either main or sub mode. [[In-system programming|In-system programmable]] AVR controllers (including blank ones) can be programmed using SPI.<ref>{{cite web |url=http://www.atmel.com/dyn/resources/prod_documents/DOC0943.PDF |title=AVR910 - In-system programming |archive-url=https://web.archive.org/web/20110302123348/http://www.atmel.com/dyn/resources/prod_documents/DOC0943.PDF |archive-date=2011-03-02}}</ref> |
|||
Chip or FPGA based designs sometimes use SPI to communicate between internal components; on-chip real estate can be as costly as its on-board cousin. |
Chip or [[FPGA]] 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]]s sometimes use SPI to interface as a sub to a host, as a main 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 |
The full-duplex capability makes SPI very simple and efficient for single main/single sub applications. Some devices use the full-duplex mode to implement an efficient, swift data stream for applications such as [[digital audio]], [[digital signal processing]], or [[channel (communications)|telecommunications channels]], but most off-the-shelf chips stick to half-duplex request/response protocols. |
||
==Variations== |
|||
SPI is used to talk to a variety of peripherals, such as: |
|||
<!-- regardless of lack of standards -->SPI implementations have a wide variety of protocol variations. Some devices are transmit-only; others are receive-only. Chip 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 === |
|||
* Sensors: temperature, pressure, [[Analog-to-digital_converter|ADC]], touchscreens |
|||
[[Motorola]] in 1983 listed<ref>{{Cite book |url=http://archive.org/details/bitsavers_motorolada8BitMicroprocessorandPeripheralData_34048525 |title=components :: motorola :: dataBooks :: 1983 Motorola 8-Bit Microprocessor and Peripheral Data}}</ref> three [[Motorola 6805|6805]] 8-bit [[Microcomputer|microcomputers]] that have an integrated "Serial Peripheral Interface", whose functionality is described in a 1984 manual.<ref>{{Cite book |url=http://archive.org/details/bitsavers_motoroladaSingleChipMicrocomputerData_68061538 |title=motorola :: dataBooks :: 1984 Motorola Single-Chip Microcomputer Data}}</ref> |
|||
* Control devices: [[Audio_codec|audio codecs]], digital potentiometers, [[Digital-to-analog_converter|DAC]] |
|||
* Communications: Ethernet, USB, USART, CAN, [[IEEE 802.15.4]] |
|||
* Memory: [[Flash_memory#Serial_flash|flash]] and EEPROM |
|||
* Real-time clocks |
|||
* LCD displays, sometimes even for managing image data |
|||
* Any [[MultiMediaCard|MMC]] or [[Secure_Digital_card|SD]] card |
|||
==== AN991 ==== |
|||
For high performance systems, [[FPGA]]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. |
|||
Motorola's 1987 Application Node AN991 "Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers"<ref>{{Cite web |title=Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers |url=http://www.bitsavers.org/components/motorola/_appNotes/AN-0991_Using_the_Serial_Peripheral_Interface_to_Communicate_between_Multiple_Microcomputers.pdf |website=[[Bitsavers]]}}</ref> (now under [[NXP Semiconductors|NXP]], last revised 2002<ref name=":4">{{cite web |date=2004 |orig-date=1994 |title=AN991/D: Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers |url=https://www.nxp.com/docs/en/application-note/AN991.pdf |url-status=live |archive-url=https://web.archive.org/web/20230404200636/https://www.nxp.com/docs/en/application-note/AN991.pdf |archive-date=2023-04-04 |access-date=2021-10-14 |website=[[NXP]]}}</ref>) informally serves as the "official" defining document for SPI. |
|||
===Timing variations=== |
|||
[[JTAG]] is essentially an application stack for SPI, using different signal names: TCK not SCK, TDI not MOSI, TDO not MISO, TMS not nCS. It defines a state machine, protocol messages, a core command set, the ability to daisy-chain devices in a "scan chain", and how vendors define new commands. Different vendors use different JTAG connectors. Bit strings used in JTAG are often long and not multiples of 8 bit words; for example, a boundary scan reports signal state on each of several hundred pins. |
|||
Some devices have timing variations from Motorola's CPOL/CPHA modes. Sending data from sub to main may use the opposite clock edge as main to sub. 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 chip select line. |
|||
== Standards == |
|||
The SPI bus is a sort of [[de facto#Standards|''de facto'' standard]], rather than one agreed by any international committee. The reason for this is probably its essential simplicity. |
|||
=== Transmission size === |
|||
However, that lack of standardization is reflected in a wide variety of protocol options. Different word sizes are common. Every device defines its own protocol, including whether or not it supports commands at all. Some devices are transmit-only; others are receive-only. Chip selects are sometimes active-high rather than active-low. Some protocols send the least significant bit first. |
|||
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 chip select === |
|||
Some devices even have minor variances from the CPOL/CPHA modes described above. 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 require an additional handshake signal to indicate when data are ready; that handshake doesn't always use MISO/MOSI signaling. Some devices have two clocks, one to "capture" or "display" data, and another to clock it into the device. Many of these "capture clocks" run from the SS line. |
|||
Some devices don't use chip select, and instead manage protocol state machine entry/exit using other methods. |
|||
=== Connectors === |
|||
There are even hardware-level differences. Some chips combine MOSI and MISO into a single data line (SI/SO); this is sometimes called "3-Wire" signaling (in contrast to normal "4-wire" SPI). Anyone needing an external connector for SPI defines their own. Signal levels depend entirely on the chips involved. |
|||
Anyone needing an external connector for SPI defines their own or uses another standard connection such as: [[UEXT]], [[Pmod Interface|Pmod]], various [[JTAG connector|JTAG connectors]], [[Secure Digital]] card socket, etc. |
|||
=== Flow control === |
|||
Some devices provide an additional signal for flow control: the device must signal "ready" after a command is issued, before the host starts clocking in response data. (Most SPI masters don't support that signal directly, and instead rely on fixed delays.) |
|||
Some devices require an additional [[Flow control (data)|flow control]] signal from sub to main, 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 sub 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 mains do not support that signal directly, and instead rely on fixed delays.) |
|||
== |
=== SafeSPI === |
||
SafeSPI<ref>[http://SafeSPI.org SafeSPI.org]</ref> is an industry standard for SPI in automotive applications. Its main focus is the transmission of sensor data between different devices. |
|||
=== High reliability modifications === |
|||
There are a number of [[hardware]] solutions to give desktop PCs, running [[Linux]], [[Mac]] or [[Microsoft Windows|Windows]] SPI master and/or slave capabilities. |
|||
In electrically noisy environments, since SPI has few signals, it can be economical to reduce the effects of [[common mode signal|common mode noise]] by adapting SPI to use [[low-voltage differential signaling]].<ref>{{cite web |title=Transmitting SPI over LVDS Interfaces |url=https://www.ti.com/lit/ug/tidued8/tidued8.pdf?ts=1613343608107&ref_url=https%253A%252F%252Fwww.google.com%252F |access-date=14 February 2021 |website=Texas Instruments}}</ref> Another advantage is that the controlled devices can be designed to loop-back to test signal integrity.<ref>{{cite web |title=SPI Master Loopback Example |url=https://developer.nordicsemi.com/nRF5_SDK/nRF51_SDK_v4.x.x/doc/html/group__spi__master__example.html |access-date=14 February 2021 |website=Nordic Semiconductor}}</ref> |
|||
{| class="wikitable" |
|||
|- |
|||
! USB to SPI adapter project |
|||
! Operating Modes |
|||
! Owner |
|||
! OS Supported |
|||
|- |
|||
| [http://www.totalphase.com/products/aardvark_i2cspi/ Aardvark I2C/SPI Host Adapter ] |
|||
| Master,Slave - up to 8 MHz |
|||
| [[Total Phase]] |
|||
| Linux,Windows,Mac |
|||
|- |
|||
| [http://www.totalphase.com/products/cheetah_spi/ Cheetah SPI Host Adapter ] |
|||
| Master - up to 50 MHz |
|||
| [[Total Phase]] |
|||
| Linux,Windows,Mac |
|||
|- |
|||
| [http://www.jovasolutions.com/hardware/tims0100_overview.htm TIMS-0102 USB to I2C and SPI Adapter ] |
|||
| Master - up to 10 MHz |
|||
| Jova Solutions |
|||
| Linux,Windows |
|||
|- |
|||
| [http://sine.ni.com/nips/cds/view/p/lang/en/nid/202368 NI USB-8541 I2C/SPI Interface] |
|||
| Master - up to 12 MHz |
|||
| [[National Instruments]] |
|||
| Windows |
|||
|- |
|||
| [http://www.byteparadigm.com/product-spi-xpress-22.html SPI Xpress] |
|||
| Master - up to 50 MHz - 4 and 3 wires |
|||
| Byte Paradigm |
|||
| Windows |
|||
|} |
|||
=== Intelligent SPI controllers === |
|||
Serial to I²C bridges are also available, for systems with no USB ports. |
|||
A '''Queued Serial Peripheral Interface''' ('''QSPI'''; different to but has same abbreviation as ''Quad SPI'' described in {{Slink|2=Quad SPI|nopage=y}}) is a type of SPI controller that uses a [[queue (data structure)|data queue]] to transfer data across an SPI bus.<ref>{{Cite web |date=1996 |orig-date=1991 |title=Freescale Semiconductor, Inc. - QSM - Queued Serial Module - Reference Manual |url=https://www.nxp.com/docs/en/reference-manual/QSMRM.pdf |url-status=dead |archive-url=https://web.archive.org/web/20190824080750/https://www.nxp.com/docs/en/reference-manual/QSMRM.pdf |archive-date=2019-08-24 |website=[[NXP]]}}</ref> It has a [[circular buffer|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 [[virtual memory|memory-mapped]] parallel devices. This feature is useful in applications such as control of an [[analog-to-digital converter|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]] (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''').{{NoteTag|Such as with the MultiChannel Serial Port Interface, or McSPI, used in Texas Instruments OMAP chips. (https://www.ti.com/product/OMAP3530)}} Most SPI main controllers integrate support for up to four chip selects,{{NoteTag|Such as the SPI controller on Atmel AT91 chips like the at91sam9G20, which is much simpler than TI's McSPI.}} although some require chip selects to be managed separately through GPIO lines. |
|||
== Protocol Analyzers == |
|||
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!<ref>{{Cite web |date=2023-01-11 |title=Quad-SPI Brings Fast Parallel Data Transmission |url=https://resources.pcb.cadence.com/blog/quad-spi-brings-fast-parallel-data-transmission |url-status=live |archive-url=https://web.archive.org/web/20230601194620/https://resources.pcb.cadence.com/blog/quad-spi-brings-fast-parallel-data-transmission |archive-date=2023-06-01 |access-date=2023-06-30 |website=[[Cadence Design Systems]] |language=en-US}}</ref> |
|||
SPI Protocol Analyzers are tools which sample an SPI bus and decode the electrical signals to provide a higher level view of the data been transmitted on the bus. Some SPI protocol analyzers are built into oscilloscopes while others are stand-alone devices. |
|||
=== Microwire === |
|||
{| class="wikitable" |
|||
Microwire,<ref>[https://www.ti.com/lit/an/snoa743/snoa743.pdf MICROWIRE Serial Interface] National Semiconductor Application Note AN-452</ref> often spelled '''μWire''', is essentially a predecessor of SPI and a trademark of [[National Semiconductor]]. 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 [[Serial Peripheral Interface#Three-wire|three-wire]] mode. |
|||
|- |
|||
! SPI Analyzer |
|||
! SPI Speeds |
|||
! Owner |
|||
! OS Supported |
|||
|- |
|||
| [http://www.totalphase.com/products/beagle_ism/ Beagle I2C/SPI/MDIO Protocol Analyzer ] |
|||
| up to 24 Mhz |
|||
| [[Total Phase]] |
|||
| Linux,Windows,Mac |
|||
|- |
|||
| [http://www.byteparadigm.com/product-spi-xpress-22.html SPI Xpress] |
|||
| up to 50 MHz |
|||
| Byte Paradigm |
|||
| Windows |
|||
|} |
|||
== |
=== Microwire/Plus === |
||
Microwire/Plus<ref>[https://www.ti.com/lit/an/snoa093/snoa093.pdf MICROWIRE/PLUS Serial Interface for COP800 Family] National Semiconductor Application Note AN-579</ref> 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. |
|||
=== Queued Serial Peripheral Interface (QSPI) === |
|||
The '''queued serial peripheral interface''' ('''QSPI''') is one type of SPI controller, not another bus type. It uses a [[Queue (data structure)|data queue]] with programmable queue pointers that allow some data transfers without [[CPU]] intervention<ref>[http://www.freescale.com/files/microcontrollers/doc/ref_manual/QSMRM.pdf Queued Serial Module Reference Manual], Freescale Semiconductor</ref>. It also has a [[memory wrap-around|wrap-around]] mode that allows continuous transfers to and from the queue with no CPU intervention. As a result, the peripherals appear to the CPU as [[virtual memory|memory-mapped]] parallel devices. This feature is useful in applications such as control of an [[Analog-to-digital converter|A/D converter]]. Other programmable features in QSPI are chip selects and transfer length/delay. |
|||
=== Three-wire === |
|||
SPI controllers from different vendors support different feature sets; such DMA queues are not uncommon, although they may be associated with separate DMA engines rather than the SPI controller itself. Most SPI master controllers integrate support for up to four chipselects, although some require chipselects to be managed separately through GPIO lines. |
|||
Three-wire variants of SPI restricted to a [[half-duplex]] mode use a single bidirectional data line called SISO (sub out/sub in) or MOMI (main out/main 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 [[Serial Peripheral Interface#Microwire|Microwire]]. Few SPI controllers support this mode, although it can be easily [[Bit-banging|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. |
|||
Microwire is essentially a predecessor of SPI. It's a strict subset: half duplex, and using SPI mode 0. (Microwire-Plus supports other SPI modes.) Microwire chips tend to need slower clock rates than newer SPI versions; perhaps 2 MHz vs 20 MHz. Some Microwire chips also support a 3-Wire mode (see below), which fits neatly with the restriction to half duplex. |
|||
This is particularly popular among SPI ROMs, which have to send a large amount of data, and comes in two variants:<ref name="W25Q16JV">{{cite web |title=W25Q16JV 3V 16M-bit serial flash memory with Dual/Quad SPI |date=12 August 2016 |version=Revision D |publisher=[[Winbond]] |type=data sheet |url=https://www.winbond.com/resource-files/w25q16jv%20spi%20revd%2008122016.pdf |access-date=2017-02-10}}</ref><ref name="D25LQ64">{{cite web |title=D25LQ64 1.8V Uniform Sector Dual and Quad SPI Flash |type=data sheet |date=11 February 2011 |version=version 0.1 |publisher=GigaDevice |url=https://www.sst-ic.com/File/DataSheet/KC909742-1112151725544ed0c4ce-8225-4c46-8d18-b81422086247.pdf |archive-url=https://web.archive.org/web/20170212090900/http://www.sst-ic.com/File/DataSheet/KC909742-1112151725544ed0c4ce-8225-4c46-8d18-b81422086247.pdf |url-status=dead |archive-date=12 February 2017 |access-date=2017-02-10}}</ref> |
|||
=== 3-Wire Serial Buses === |
|||
As mentioned above, one variant of SPI uses single bidirectional data line (Slave Out/Slave IN, called SISO) instead of two unidirectional ones (MOSI and MISO). Clearly, this variant is restricted to a half duplex mode. It tends to be used for lower performance parts, such as small EEPROMs used only during system startup and certain sensors, and Microwire. As of this writing, few SPI master controllers support this mode; although it can often be easily [[Bit-banging|bit-banged]] in software. |
|||
* Dual read commands the send and address from the main in single mode, and return the data in dual mode. |
|||
When someone says a part supports SPI or Microwire, you can normally assume that means the four-wire version. |
|||
* Dual I/O commands send the command in single mode, then send the address and return data in dual mode. |
|||
=== Quad SPI === |
|||
However, when someone talks about a part supporting a 3-Wire serial bus you should always find out what they mean. They might mean standard four-wire SPI ... excluding the chipselect pin from that count, since most buses use chipselects but only three wires carry "real" signals. (Plus, sometimes with an unshared SPI bus segment the device's chipselect will be hard-wired as "always selected".) They might mean "real" 3-wire SPI. They might even mean an [[RS-232#3-wire_and_5-wire_RS-232|RS232 cable]] with just RXD, TXD, and shield/ground, or an application-specific signaling scheme. |
|||
'''Quad SPI''' ('''QSPI'''; different to but has same abbreviation as ''Queued-SPI'' described in {{Slink|2=Intelligent SPI controllers|nopage=y}}) 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.{{r|W25Q16JV|D25LQ64}} |
|||
; SQI Type 1: Commands sent on single line but addresses and data sent on four lines |
|||
== References == |
|||
; SQI Type 2: Commands and addresses sent on a single line but data sent/received on four lines |
|||
=== QPI/SQI === |
|||
<references /> |
|||
Further extending quad SPI, some devices support a "quad everything" mode where ''all'' communication takes place over 4 data lines, including commands.<ref>{{cite web |url=https://community.nxp.com/thread/336422 |title=QuadSPI flash: Quad SPI mode vs. QPI mode |date=December 2014 |website=NXP community forums |access-date=2016-02-10}}</ref> This is variously called "QPI"{{r|D25LQ64}} (not to be confused with [[Intel QuickPath Interconnect]]) or "serial quad I/O" (SQI)<ref name="SST26VF032B">{{cite web |title=SST26VF032B / SST26VF032BA 2.5V/3.0V 32 Mbit Serial Quad I/O (SQI) Flash Memory |type=Data sheet |publisher=[[Microchip, Inc.]] |date=2017 |version=version E |url=http://ww1.microchip.com/downloads/en/DeviceDoc/20005218E.pdf |access-date=2017-02-10}}</ref> |
|||
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]] transmission.<ref>{{Cite web |first=David |last=Patterson |url=https://www.nxp.com/files/32bit/doc/app_note/AN4512.pdf |title=Quad Serial Peripheral Interface (QuadSPI) Module Updates |type=Application note |date=May 2012 |access-date=September 21, 2016 |publisher=[[Freescale Semiconductor]]}}</ref><ref>{{cite news |title=Improving performance using SPI-DDR NOR flash memory |first=Rich |last=Pell |date=13 October 2011 |journal=[[EDN (magazine)|EDN]] |url=https://www.edn.com/design/systems-design/4368499/Improving-performance-using-SPI-DDR-NOR-flash-memory-4368499}}</ref> |
|||
=== JTAG === |
|||
{{Main articles|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 [[Boundary scan|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.<ref>IEEE 1149.1-2013</ref> |
|||
=== SGPIO === |
|||
{{Main articles|SGPIO}} |
|||
[[SGPIO]] is essentially another (incompatible) application stack for SPI designed for particular backplane management activities.{{citation needed|date=July 2010}} SGPIO uses 3-bit messages. |
|||
===Intel's Enhanced Serial Peripheral Interface=== |
|||
[[Intel]] 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 signal|out-of-band]] pins through eSPI, and allow system designers to trade off cost and performance.<ref name="eSPI">{{cite report |title=Enhanced Serial Peripheral Interface (eSPI) Interface Base Specification (for Client and Server Platforms) |date=January 2016 |version=Revision 1.0 |url=https://www-ssl.intel.com/content/dam/support/us/en/documents/software/chipset-software/327432-004_espi_base_specification_rev1.0_cb.pdf |publisher=Intel |access-date=2017-02-05 |id=Document number 327432-004}}</ref><ref>{{cite report |id=Document Number 327432-001EN |title=Enhanced Serial Peripheral Interface (eSPI) Interface Specification (for Client Platforms) |date=May 2012 |version=Revision 0.6 |url=https://downloadmirror.intel.com/21353/eng/eSPI%20Specification%20rev0.6%20(client).pdf |publisher=Intel |access-date=2017-02-05}}</ref> |
|||
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.<ref name="eSPI" /> |
|||
This standard defines an Alert# signal that is used by an eSPI sub to request service from the main. In a performance-oriented design or a design with only one eSPI sub, each eSPI sub will have its Alert# pin connected to an Alert# pin on the eSPI main that is dedicated to each sub, allowing the eSPI main to grant low-latency service, because the eSPI main will know which eSPI sub needs service and will not need to poll all of the subs to determine which device needs service. In a budget design with more than one eSPI sub, all of the Alert# pins of the subs are connected to one Alert# pin on the eSPI main in a [[wired-OR]] connection, which requires the main to poll all the subs 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 subs needing service and therefore pulling the Alert# signal low.<ref name="eSPI" /> |
|||
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.<ref name="eSPI" /> |
|||
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.<ref name="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 subs 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.<ref name="eSPI" /> |
|||
eSPI subs are allowed to use the eSPI main as a proxy to perform flash operations on a standard SPI flash memory sub on behalf of the requesting eSPI sub.<ref name="eSPI" /> |
|||
64-bit memory addressing is also added, but is only permitted when there is no equivalent 32-bit address.<ref name="eSPI" /> |
|||
The Intel [[Z170|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.<ref>{{Cite web | url = https://www.intel.com/content/dam/www/public/us/en/documents/datasheets/100-series-chipset-datasheet-vol-1.pdf | title = Intel® 100 Series Chipset Family PCH Datasheet, Vol. 1 | access-date = April 15, 2015}}</ref> |
|||
The eSPI bus is also adopted by [[AMD Ryzen]] chipsets. |
|||
==Development tools== |
|||
=== Single-board computers === |
|||
[[Single-board computers]] may provide [[Lead (electronics)|pin]] access to SPI hardware units. For instance, the [[Raspberry Pi#J8 header and general purpose input-output (GPIO)|Raspberry Pi's J8 header]] exposes at least two SPI units that can be used via [[Linux]] [[Device driver|drivers]] or [[Python (programming language)|python]]. |
|||
=== USB to SPI adapters === |
|||
There are a number of [[USB]] adapters that allow a desktop [[Personal computer|PC]] or [[smartphone]] with [[USB]] to communicate with SPI chips (e.g. [[FTDI|FT]]221xs<ref>{{cite web |title=USB to SPI converter |url=https://ftdichip.com/products/ft221xs/ |access-date=14 February 2021 |website=FTDI|date=2 August 2020 }}</ref>). They are used for embedded systems, chips ([[FPGA]], [[Application-specific integrated circuit|ASIC]], and [[System on a chip|SoC]]) and peripheral testing, programming and debugging. Many of them also provide scripting or programming capabilities (e.g. [[Visual Basic]], [[C (programming language)|C]]/[[C++]], [[VHDL]]). |
|||
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<ref>[https://www.byteparadigm.com/product-spi-storm-39.html SPI Storm – Serial Protocol Host Adapter] with support of custom serial protocols, Byte Paradigm.</ref>). |
|||
===Protocol analyzers=== |
|||
{{Main articles|Logic analyzer}} |
|||
[[Logic analyzers]] are tools which collect, [[timestamp]], analyze, decode, store, and view the high-speed waveforms, to help [[Debugging|debug]] 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]] can be seen on [[Analog signal|analog]] channels (and/or via [[Digital signal|digital]] channels in [[Oscilloscope#Mixed-signal oscilloscope|mixed-signal oscilloscopes]]).<ref>{{cite web |title=N5391B I²C and SPI Protocol Triggering and Decode for Infiniium scopes |url=https://www.keysight.com/en/pd-1646694-pn-N5391B/ic-and-spi-protocol-triggering-and-decode?cc=US&lc=eng}}</ref> Most [[oscilloscope]] vendors offer optional support for SPI protocol analysis (both 2-, [[Serial Peripheral Interface#Three-wire|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 |
|||
* Main out, sub in (MOSI) |
|||
** SIMO, MTSR, SPID - correspond to MOSI on both main and sub devices, connects to each other |
|||
** SDI, DI, DIN, SI, SDA - on sub devices; various abbreviations for ''serial data in''; connects to MOSI on main |
|||
** SDO, DO, DOUT, SO - on main devices; various abbreviations for ''serial data out''; connects to MOSI on sub |
|||
** COPI, PICO for ''peripheral'' and ''controller'',<ref name="OSHWA">[https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/ SPI; OSHWA.]</ref><ref name=":5">https://www.ti.com/lit/an/scea091a/scea091a.pdf {{Bare URL PDF|date=August 2024}}</ref> or COTI for ''controller'' and ''target''<ref name=":1">{{Cite web |title=Serial Peripheral Interface (SPI) Devices |url=https://www.nxp.com/products/interfaces/ic-spi-i3c-interface-devices/www.nxp.com/pages/:SPI |url-status=live |archive-url=https://web.archive.org/web/20230601020101/https://www.nxp.com/products/interfaces/ic-spi-i3c-interface-devices/spi-interface-devices:SPI |archive-date=2023-06-01 |access-date=2023-07-22 |website=[[NXP]]}}</ref> |
|||
* Main in, sub out (MISO) |
|||
** SOMI, MRST, SPIQ - correspond to MISO on both main and sub devices, connects to each other |
|||
** SDO, DO, DOUT, SO - on sub devices; connects to MISO on main |
|||
** SDI, DI, DIN, SI - on main devices; connects to MISO on sub |
|||
** CIPO, POCI,<ref name="OSHWA" /><ref name=":5" /> or CITO<ref name=":1" /> |
|||
* Chip select (CS) |
|||
** CE (chip enable) |
|||
** Historical: SS (slave select), SSEL, NSS, /SS, SS# (sub select) |
|||
[[Microchip Technology|Microchip]] uses ''host'' and ''client'' though keeps the abbreviation MOSI and MISO.<ref>{{Cite web |last=Stoicescu |first=Alin |title=Getting Started with Serial Peripheral Interface (SPI) |url=https://onlinedocs.microchip.com/pr/GUID-EF58F3A9-B49B-4C31-A7EC-B71EBB831870-en-US-5/index.html |url-status=live |archive-url=https://web.archive.org/web/20231221205244/https://onlinedocs.microchip.com/pr/GUID-EF58F3A9-B49B-4C31-A7EC-B71EBB831870-en-US-5/index.html |archive-date=2023-12-21 |access-date=2023-12-21 |website=[[Microchip Technology]]}}</ref> |
|||
==See also== |
==See also== |
||
{{Portal|Electronics}} |
|||
*[[I²C|I<sup>2</sup>C]], sometimes called "2-wire" bus |
|||
* [[List of network buses]] |
|||
*[[1-Wire]] |
|||
*[[Microwire]] |
|||
==Notes== |
|||
*[[Computer bus]] |
|||
{{NoteFoot}} |
|||
*[[Controller Area Network]] |
|||
*[[Serial communications]] |
|||
==References== |
|||
*[[Synchronous_Serial_Port | Synchronous Serial Port (SSP)]] |
|||
{{reflist|30em}} |
|||
*[[Peripheral]] |
|||
*[[Interface]] |
|||
==External links== |
==External links== |
||
{{Commons category|Serial Peripheral Interface}} |
|||
*[https://www.intel.com/content/www/us/en/support/software/chipset-software/000020952.html Intel eSPI (Enhanced Serial Peripheral Interface)] |
|||
*[http://www.epanorama.net/links/serialbus.html Serial buses information page] |
|||
*[ |
*[https://www.corelis.com/education/SPI_Tutorial.htm SPI Tutorial] |
||
*[http://www.serialflash.com/ Serial Flash] Lots of good information on SPI part manufacturers and models. |
|||
*[http://ww1.microchip.com/downloads/en/DeviceDoc/spi.pdf SPI - PICmicro Serial Peripheral Interface] Microchip (company) tutorial on SPI. |
|||
[[Category:Serial buses]] |
|||
{{Computer bus}} |
|||
[[cs:SPI]] |
|||
[[de:Serial Peripheral Interface]] |
|||
[[ |
[[Category:Interfaces]] |
||
[[Category:Computer buses]] |
|||
[[fr:Serial Peripheral Interface]] |
|||
[[Category:Computer hardware standards]] |
|||
[[it:Serial Peripheral Interface]] |
|||
[[Category:Serial buses]] |
|||
[[ja:シリアル・ペリフェラル・インタフェース]] |
|||
[[no:SPI]] |
|||
[[pl:Serial Peripheral Interface]] |
|||
[[pt:Serial Peripheral Interface]] |
|||
[[ru:Serial Peripheral Interface]] |
|||
[[zh:序列周邊介面]] |
Latest revision as of 05:43, 7 December 2024
This article may need to be rewritten to comply with Wikipedia's quality standards, as it reads like a guide or textbook. (March 2021) |
This article appears to be slanted towards recent events. (December 2023) |
Type | Serial communication bus | ||
---|---|---|---|
Production history | |||
Designer | Motorola | ||
Designed | Around early 1980s[note 1] | ||
Manufacturer | various | ||
Daisy chain | Depends on devices | ||
Connector | Unspecified | ||
Electrical | |||
Max. voltage | Unspecified | ||
Max. current | Unspecified | ||
Data | |||
Width | 1 bit (bidirectional) | ||
Max. devices | Multidrop limited by chip selects. Daisy chaining unlimited. | ||
Protocol | Full-duplex serial | ||
Pinout | |||
MOSI | Master Out Slave In | ||
MISO | Master In Slave Out | ||
SCLK | Serial Clock | ||
CS | Chip Select (one or more) | ||
(pins may have alternative names) |
Serial Peripheral Interface (SPI) is a de facto standard (with many variants) for synchronous serial communication, used primarily in embedded systems for short-distance wired communication between integrated circuits.
SPI follows a master–slave architecture, [1] called main–sub herein, [note 2] [note 3] where one[note 4] main device orchestrates communication with one or more sub (peripheral) devices by driving the clock and chip select signals.
Motorola'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, and with the two-wire I²C and 1-Wire serial buses.
Typical applications include interfacing microcontrollers with peripheral chips for Secure Digital cards, liquid crystal displays, analog-to-digital and digital-to-analog converters, flash and EEPROM memory, and various communication chips.
Although SPI is a synchronous serial interface,[2] it is different from Synchronous Serial Interface (SSI). SSI employs differential signaling and provides only a single simplex communication channel.
Operation
[edit]Commonly, SPI has four logic signals. Variations may use different names or have different signals. Historical terms are shown in parentheses.
Abbr. Name Description CSchip selectActive-low chip select signal from main to
enable communication with a specific sub deviceSCLKserial clockClock signal from main MOSImain out, sub in
(master out, slave in)Serial data from main, most-significant bit first MISOmain in, sub out
(master in, slave out)Serial data from sub, most-significant bit first
MOSI on a main outputs to MOSI on a sub. MISO on a sub outputs to MISO on a main.
Each device internally uses a shift register for serial communication, which together forms an inter-chip circular buffer.
Sub devices should use tri-state outputs so their MISO signal becomes high impedance (electrically disconnected) when the device is not selected. Subs without tri-state outputs cannot share a MISO line with other subs without using an external tri-state buffer.
Data transmission
[edit]To begin communication, the SPI main first selects a sub device by pulling its CS low. (Note: the bar above CS 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 main must wait for at least that period of time before issuing clock cycles.[note 5]
During each SPI clock cycle, full-duplex transmission of a single bit occurs. The main sends a bit on the MOSI line while the sub 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 sub (Figure 1) involves one shift register in the main and one shift register in the sub, both of some given word size (e.g. 8 bits),[note 6] connected in a virtual ring topology. Data is usually shifted out with the most-significant bit (MSB) first.[note 7] On the clock edge, both main and sub 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 main and sub 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 main stops toggling the clock signal, and typically deselects the sub.
If a single sub device is used, its CS pin may be fixed to logic low if the sub permits it. With multiple sub devices, a multidrop configuration requires an independent CS signal from the main for each sub device, while a daisy-chain configuration only requires one CS signal.
Every sub on the bus that has not been selected should disregard the input clock and MOSI signals. And to prevent contention on MISO, non-selected subs must use tristate output. Subs that aren't already tristate will need external tristate buffers to ensure this.[3]
Clock polarity and phase
[edit]In addition to setting the clock frequency, the main must also configure the clock polarity and phase with respect to the data. Motorola[4][5] 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.
- SCLKCPOL=0 is a clock which idles at the logical low voltage.
- SCLKCPOL=1 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 CS 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 CS 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.
- Note: 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 main and sub devices may sample data at different points in that half cycle, for flexibility, despite the original specification.
- For CPHA=0:
Mode numbers
[edit]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:
SPI mode | Clock polarity (CPOL) |
Clock phase (CPHA) |
Data is shifted out on | Data is sampled on |
---|---|---|---|---|
0 | 0 | 0 | falling SCLK, and when CS activates | rising SCLK |
1 | 0 | 1 | rising SCLK | falling SCLK |
2 | 1 | 0 | rising SCLK, and when CS activates | falling SCLK |
3 | 1 | 1 | falling SCLK | rising SCLK |
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 main 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
[edit]Some sub 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
[edit]Interrupts are outside the scope of SPI; their usage is neither forbidden nor specified, and so may optionally be implemented.
From main to sub
[edit]Microcontrollers configured as sub devices may have hardware support for generating interrupt signals to themselves when data words are received or overflow occurs in a receive FIFO buffer,[6] and may also set up an interrupt routine when their chip select input line is pulled low or high.
From sub to main
[edit]SPI subs sometimes use an out-of-band signal (another wire) to send an interrupt signal to a main. Examples include pen-down interrupts from touchscreen sensors, thermal limit alerts from temperature sensors, alarms issued by real-time clock chips, SDIO[note 8] and audio jack insertions for an audio codec. Interrupts to main may also be faked by using polling (similarly to USB 1.1 and 2.0).
Software design
[edit]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
[edit]The pseudocode below outlines a software implementation ("bit-banging") of SPI's protocol as a main with simultaneous output and input. This pseudocode is for CPHA=0 and CPOL=0, thus SCLK is pulled low before CS 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 CS as high
- Pull CS low to select the sub
- Loop for however many number of bytes to transfer:[note 9]
- Initialize
byte_out
with the next output byte to transmit - Loop 8 times:
- Left-Shift[note 10] the next output bit from
byte_out
to MOSI - NOP for the sub's setup time
- Pull SCLK high
- Left-Shift the next input bit from MISO into
byte_in
- NOP for the sub's hold time
- Pull SCLK low
- Left-Shift[note 10] the next output bit from
byte_in
now contains that recently-received byte and can be used as desired
- Initialize
- Pull CS high to unselect the sub
Bit-banging a sub's protocol is similar but different from above. An implementation might involve busy waiting for CS to fall or triggering an interrupt routine when CS falls, and then shifting in and out bits when the received SCLK changes appropriately for however long the transfer size is.
Bus topologies
[edit]Though the previous operation section focused on a basic interface with a single sub, SPI can instead communicate with multiple subs using multidrop, daisy chain, or expander configurations.
Multidrop configuration
[edit]In the multidrop bus configuration, each sub has its own CS, and the main 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 subs 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 sub is not selected. Sub devices not supporting tri-state may be used in multidrop configuration by adding a tri-state buffer chip controlled by its CS signal.[3] (Since only a single signal line needs to be tristated per sub, one typical standard logic chip that contains four tristate buffers with independent gate inputs can be used to interface up to four sub devices to an SPI bus)
Caveat: All CS signals should start high (to indicate no chips are selected) before sending initialization messages to any sub, so other uninitialized subs ignore messages not addressed to them. This is a concern if the main uses general-purpose input/output (GPIO) pins (which may default to an undefined state) for CS and if the main uses separate software libraries to initialize each device. One solution is to configure all GPIOs used for CS to output a high voltage for all subs before running initialization code from any of those software libraries. Another solution is to add a pull-up resistor on each CS, to ensure that all CS signals are initially high.[3]
Daisy chain configuration
[edit]Some products that implement SPI may be connected in a daisy chain configuration, where the first sub's output is connected to the second sub's input, and so on with subsequent subs, until the final sub, whose output is connected back to the main's input. This effectively merges the individual communication shift registers of each sub to form a single larger combined shift register that shifts data through the chain. This configuration only requires a single CS line from the main, rather than a separate CS line for each sub.[7]
In addition to using SPI-specific subs, daisy-chained SPI can include discrete shift registers for more pins of inputs (e.g. using the parallel-in serial-out 74xx165)[8] or outputs (e.g. using the serial-in parallel-out 74xx595)[9] chained indefinitely. Other applications that can potentially interoperate with daisy-chained SPI include SGPIO, JTAG,[10] and I2C.
Expander configurations
[edit]Expander configurations use SPI-controlled addressing units (e.g. binary decoders, demultiplexers, or shift registers) to add chip selects.
For example, one CS can be used for transmitting to a SPI-controlled demultiplexer an index number controlling its select signals, while another CS is routed through that demultiplexer according to that index to select the desired sub.[11]
Pros and cons
[edit]Advantages
[edit]- 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 than I²C or SMBus
- SPI's protocol has no maximum clock speed, however:
- Individual devices specify acceptable clock frequencies
- Wiring and electronics limit frequency
- SPI's protocol has no maximum clock speed, however:
- 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 subs only requires a selectable shift register
- 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 (CS); all others are shared
- Note: the daisy-chain configuration doesn't need more than one shared CS
- At most one unique signal per device (CS); all others are shared
- Typically lower power requirements than I²C or SMBus due to less circuitry (including pull up resistors)
- Single main 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
[edit]- Requires more pins on IC packages than I²C, even in three-wire variants
- Only handles short distances compared to RS-232, RS-485, or CAN-bus (though distance can be extended with the use of transceivers like RS-422)
- Extensibility severely reduced when multiple subs using different SPI Modes are required
- Access is slowed down when main 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 sub (but the main can delay the next clock edge to slow the transfer rate)
- No hardware sub acknowledgment (the main could be transmitting to nowhere and not know it)
- No error-checking protocol
- No hot swapping (dynamically adding nodes)
- Interrupts are outside the scope of SPI (see § Interrupts)
Applications
[edit]SPI is used to talk to a variety of peripherals, such as
- Sensors: temperature, pressure, ADC, touchscreens, video game controllers
- Control devices: audio codecs, digital potentiometers, DACs
- Camera lenses: Canon EF lens mount
- Communications: Ethernet, USB, USART, CAN, IEEE 802.15.4, IEEE 802.11
- Memory: flash and EEPROMs
- Real-time clocks
- LCDs, sometimes even for managing image data
- Any MMC or SD card (including SDIO variant[note 8])
- Shift registers for additional I/O[8][9]
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 processors, both with higher-end 32-bit processors such as those using ARM, MIPS, or PowerPC and with lower-end microcontrollers such as the AVR, PIC, and MSP430. These chips usually include SPI controllers capable of running in either main or sub mode. In-system programmable AVR controllers (including blank ones) can be programmed using SPI.[12]
Chip or FPGA 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, FPGAs sometimes use SPI to interface as a sub to a host, as a main 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 main/single sub applications. Some devices use the full-duplex mode to implement an efficient, swift data stream for applications such as digital audio, digital signal processing, or telecommunications channels, but most off-the-shelf chips stick to half-duplex request/response protocols.
Variations
[edit]SPI implementations have a wide variety of protocol variations. Some devices are transmit-only; others are receive-only. Chip 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
[edit]Motorola in 1983 listed[13] three 6805 8-bit microcomputers that have an integrated "Serial Peripheral Interface", whose functionality is described in a 1984 manual.[14]
AN991
[edit]Motorola's 1987 Application Node AN991 "Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers"[15] (now under NXP, last revised 2002[5]) informally serves as the "official" defining document for SPI.
Timing variations
[edit]Some devices have timing variations from Motorola's CPOL/CPHA modes. Sending data from sub to main may use the opposite clock edge as main to sub. 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 chip select line.
Transmission size
[edit]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 chip select
[edit]Some devices don't use chip select, and instead manage protocol state machine entry/exit using other methods.
Connectors
[edit]Anyone needing an external connector for SPI defines their own or uses another standard connection such as: UEXT, Pmod, various JTAG connectors, Secure Digital card socket, etc.
Flow control
[edit]Some devices require an additional flow control signal from sub to main, 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 sub 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 mains do not support that signal directly, and instead rely on fixed delays.)
SafeSPI
[edit]SafeSPI[16] is an industry standard for SPI in automotive applications. Its main focus is the transmission of sensor data between different devices.
High reliability modifications
[edit]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.[17] Another advantage is that the controlled devices can be designed to loop-back to test signal integrity.[18]
Intelligent SPI controllers
[edit]A Queued Serial Peripheral Interface (QSPI; different to but has same abbreviation as Quad SPI described in § Quad SPI) is a type of SPI controller that uses a data queue to transfer data across an SPI bus.[19] 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 (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).[note 11] Most SPI main controllers integrate support for up to four chip selects,[note 12] although some require chip 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![20]
Microwire
[edit]Microwire,[21] often spelled μWire, is essentially a predecessor of SPI and a trademark of National Semiconductor. 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
[edit]Microwire/Plus[22] 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
[edit]Three-wire variants of SPI restricted to a half-duplex mode use a single bidirectional data line called SISO (sub out/sub in) or MOMI (main out/main 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
[edit]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:[23][24]
- Dual read commands the send and address from the main in single mode, and return the data in dual mode.
- Dual I/O commands send the command in single mode, then send the address and return data in dual mode.
Quad SPI
[edit]Quad SPI (QSPI; different to but has same abbreviation as Queued-SPI described in § Intelligent SPI controllers) 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.[23][24]
- 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
[edit]Further extending quad SPI, some devices support a "quad everything" mode where all communication takes place over 4 data lines, including commands.[25] This is variously called "QPI"[24] (not to be confused with Intel QuickPath Interconnect) or "serial quad I/O" (SQI)[26]
This requires programming a configuration bit in the device and requires care after reset to establish communication.
Double data rate
[edit]In addition to using multiple lines for I/O, some devices increase the transfer rate by using double data rate transmission.[27][28]
JTAG
[edit]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.[29]
SGPIO
[edit]SGPIO is essentially another (incompatible) application stack for SPI designed for particular backplane management activities.[citation needed] SGPIO uses 3-bit messages.
Intel's Enhanced Serial Peripheral Interface
[edit]Intel 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.[30][31]
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.[30]
This standard defines an Alert# signal that is used by an eSPI sub to request service from the main. In a performance-oriented design or a design with only one eSPI sub, each eSPI sub will have its Alert# pin connected to an Alert# pin on the eSPI main that is dedicated to each sub, allowing the eSPI main to grant low-latency service, because the eSPI main will know which eSPI sub needs service and will not need to poll all of the subs to determine which device needs service. In a budget design with more than one eSPI sub, all of the Alert# pins of the subs are connected to one Alert# pin on the eSPI main in a wired-OR connection, which requires the main to poll all the subs 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 subs needing service and therefore pulling the Alert# signal low.[30]
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.[30]
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.[30]
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 subs 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.[30]
eSPI subs are allowed to use the eSPI main as a proxy to perform flash operations on a standard SPI flash memory sub on behalf of the requesting eSPI sub.[30]
64-bit memory addressing is also added, but is only permitted when there is no equivalent 32-bit address.[30]
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.[32]
The eSPI bus is also adopted by AMD Ryzen chipsets.
Development tools
[edit]Single-board computers
[edit]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 drivers or python.
USB to SPI adapters
[edit]There are a number of USB adapters that allow a desktop PC or smartphone with USB to communicate with SPI chips (e.g. FT221xs[33]). They are used for embedded systems, chips (FPGA, ASIC, and SoC) and peripheral testing, programming and debugging. Many of them also provide scripting or programming capabilities (e.g. Visual Basic, C/C++, VHDL).
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[34]).
Protocol analyzers
[edit]Logic analyzers are tools which collect, timestamp, analyze, decode, store, and view the high-speed waveforms, to help debug and develop. Most logic analyzers have the capability to decode SPI bus signals into high-level protocol data with human-readable labels.
Oscilloscopes
[edit]SPI waveforms can be seen on analog channels (and/or via digital channels in mixed-signal oscilloscopes).[35] Most oscilloscope vendors offer optional support for SPI protocol analysis (both 2-, 3-, and 4-wire SPI) with triggering.
Alternative terminology
[edit]Various alternative abbreviations for the four common SPI signals are used. (This section omits overbars indicating active-low.)
- Serial clock
- SCK, SCLK, CLK, SCL
- Main out, sub in (MOSI)
- SIMO, MTSR, SPID - correspond to MOSI on both main and sub devices, connects to each other
- SDI, DI, DIN, SI, SDA - on sub devices; various abbreviations for serial data in; connects to MOSI on main
- SDO, DO, DOUT, SO - on main devices; various abbreviations for serial data out; connects to MOSI on sub
- COPI, PICO for peripheral and controller,[36][37] or COTI for controller and target[38]
- Main in, sub out (MISO)
- Chip select (CS)
- CE (chip enable)
- Historical: SS (slave select), SSEL, NSS, /SS, SS# (sub select)
Microchip uses host and client though keeps the abbreviation MOSI and MISO.[39]
See also
[edit]Notes
[edit]- ^ The earliest definitive mention of a "Serial Peripheral Interface" in bitsavers archives of Motorola manuals is from 1983 (see § Original definition). While some sources on the web allege that Motorola introduced SPI when 68000 was introduced in 1979, however many of those appear to be citogenesis or speculation, and Motorola's 1983 68000 manual has no mention of "Serial Peripheral Interface", so the alleged 1979 date doesn't seem to be reliable information. Please only add a specific design_date if you have a definitive source from Motorola around then.
- ^ Using main and sub maintains the same initial letters to remain in sync with the line names. For example MISO could be expanded as "main in, sub out"
- ^ The § Alternative terminology section gives more details on proposed alternative terminology. See the talk page for an ongoing discussion.
- ^ For any given transaction, only one device is the main. However, some devices support changing main and sub roles on the fly. Most microcontrollers can easily reconfigure their SPI's role, and some Atmel and Silabs devices can change roles depending on an external pin.
- ^ Some subs require a falling edge of the Chip Select signal to initiate an action. An example is the Maxim MAX1242 ADC, which starts conversion on a high→low transition.
- ^ Transmissions often consist of eight-bit words. However, 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.
- ^ The original specification has a LSBFE ("LSB-First Enable") to control whether data is transferred least (LSB) or most significant bit (MSB) first.
- ^ a b Not to be confused with the SDIO (Serial Data I/O) line of the half-duplex implementation of SPI sometimes also called "3-wire" SPI. Here e.g. MOSI (via a resistor) and MISO (no resistor) of a main is connected to the SDIO line of a sub.
- ^ Peripherals may allow or require a particular number (or any number) of transfer bytes while selected, as specified in their datasheet.
- ^ Left-shifts are used because SPI normally transmits the most-significant bit first. Right-shifts could instead be used to transfer least-significant bit first.
- ^ Such as with the MultiChannel Serial Port Interface, or McSPI, used in Texas Instruments OMAP chips. (https://www.ti.com/product/OMAP3530)
- ^ Such as the SPI controller on Atmel AT91 chips like the at91sam9G20, which is much simpler than TI's McSPI.
References
[edit]- ^ Dhaker, Piyu (2018). "Introduction to SPI Interface". Analog Dialogue. Archived from the original on 2023-05-25. Retrieved 2023-07-21.
- ^ "What is Serial Synchronous Interface (SSI)?". Retrieved 2015-01-28.
- ^ a b c Better SPI Bus Design in 3 Steps
- ^ SPI Block Guide v3.06; Motorola/Freescale/NXP; 2003.
- ^ a b "AN991/D: Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers" (PDF). NXP. 2004 [1994]. Archived (PDF) from the original on 2023-04-04. Retrieved 2021-10-14.
- ^ "TMS320x281x Serial Peripheral Interface Reference Guide". Texas Instruments. 2002. pp. 16–17.
- ^ Maxim-IC application note 3947: "Daisy-Chaining SPI Devices"
- ^ a b Gammon, Nick (2013-03-23). "Gammon Forum : Electronics : Microprocessors : Using a 74HC165 input shift register". Gammon Forum. Archived from the original on 2023-07-29. Retrieved 2023-08-03.
- ^ a b Gammon, Nick (2012-01-31). "Gammon Forum : Electronics : Microprocessors : Using a 74HC595 output shift register as a port-expander". Gammon Forum. Archived from the original on 2023-07-14. Retrieved 2023-08-03.
- ^ Interfaces, 1977, pp. 80, 84
- ^ "Serial-Control Multiplexer Expands SPI Chip Selects" (PDF). Premier Farnell. 2001-07-01. Archived from the original (PDF) on 2019-08-19.
- ^ "AVR910 - In-system programming" (PDF). Archived from the original (PDF) on 2011-03-02.
- ^ components :: motorola :: dataBooks :: 1983 Motorola 8-Bit Microprocessor and Peripheral Data.
- ^ motorola :: dataBooks :: 1984 Motorola Single-Chip Microcomputer Data.
- ^ "Using the Serial Peripheral Interface to Communicate Between Multiple Microcomputers" (PDF). Bitsavers.
- ^ SafeSPI.org
- ^ "Transmitting SPI over LVDS Interfaces" (PDF). Texas Instruments. Retrieved 14 February 2021.
- ^ "SPI Master Loopback Example". Nordic Semiconductor. Retrieved 14 February 2021.
- ^ "Freescale Semiconductor, Inc. - QSM - Queued Serial Module - Reference Manual" (PDF). NXP. 1996 [1991]. Archived from the original (PDF) on 2019-08-24.
- ^ "Quad-SPI Brings Fast Parallel Data Transmission". Cadence Design Systems. 2023-01-11. Archived from the original on 2023-06-01. Retrieved 2023-06-30.
- ^ MICROWIRE Serial Interface National Semiconductor Application Note AN-452
- ^ MICROWIRE/PLUS Serial Interface for COP800 Family National Semiconductor Application Note AN-579
- ^ a b "W25Q16JV 3V 16M-bit serial flash memory with Dual/Quad SPI" (PDF) (data sheet). Revision D. Winbond. 12 August 2016. Retrieved 2017-02-10.
- ^ a b c "D25LQ64 1.8V Uniform Sector Dual and Quad SPI Flash" (PDF) (data sheet). version 0.1. GigaDevice. 11 February 2011. Archived from the original (PDF) on 12 February 2017. Retrieved 2017-02-10.
- ^ "QuadSPI flash: Quad SPI mode vs. QPI mode". NXP community forums. December 2014. Retrieved 2016-02-10.
- ^ "SST26VF032B / SST26VF032BA 2.5V/3.0V 32 Mbit Serial Quad I/O (SQI) Flash Memory" (PDF) (Data sheet). version E. Microchip, Inc. 2017. Retrieved 2017-02-10.
- ^ Patterson, David (May 2012). "Quad Serial Peripheral Interface (QuadSPI) Module Updates" (PDF) (Application note). Freescale Semiconductor. Retrieved September 21, 2016.
- ^ Pell, Rich (13 October 2011). "Improving performance using SPI-DDR NOR flash memory". EDN.
- ^ IEEE 1149.1-2013
- ^ a b c d e f g h Enhanced Serial Peripheral Interface (eSPI) Interface Base Specification (for Client and Server Platforms) (PDF) (Report). Revision 1.0. Intel. January 2016. Document number 327432-004. Retrieved 2017-02-05.
- ^ Enhanced Serial Peripheral Interface (eSPI) Interface Specification (for Client Platforms) (PDF) (Report). Revision 0.6. Intel. May 2012. Document Number 327432-001EN. Retrieved 2017-02-05.
- ^ "Intel® 100 Series Chipset Family PCH Datasheet, Vol. 1" (PDF). Retrieved April 15, 2015.
- ^ "USB to SPI converter". FTDI. 2 August 2020. Retrieved 14 February 2021.
- ^ SPI Storm – Serial Protocol Host Adapter with support of custom serial protocols, Byte Paradigm.
- ^ "N5391B I²C and SPI Protocol Triggering and Decode for Infiniium scopes".
- ^ a b SPI; OSHWA.
- ^ a b https://www.ti.com/lit/an/scea091a/scea091a.pdf [bare URL PDF]
- ^ a b "Serial Peripheral Interface (SPI) Devices". NXP. Archived from the original on 2023-06-01. Retrieved 2023-07-22.
- ^ Stoicescu, Alin. "Getting Started with Serial Peripheral Interface (SPI)". Microchip Technology. Archived from the original on 2023-12-21. Retrieved 2023-12-21.