Saturday, February 11, 2012

Serial Peripheral Interface Bus

The Consecutive Peripheral Interface Bus or SPI (pronounced like "S.P.I." or "spy") bus is a ancillary consecutive abstracts hotlink accepted alleged by Motorola that operates in abounding bifold mode. Accessories acquaint in master/slave approach area the adept accessory initiates the abstracts frame. Multiple bondservant accessories are accustomed with alone bondservant baddest (chip select) lines. Sometimes SPI is alleged a "four-wire" consecutive bus, allegory with three-, two-, and one-wire consecutive buses.

Operation

The SPI bus can accomplish with a individual adept accessory and with one or added bondservant devices.

If a individual bondservant accessory is used, the SS pin may be anchored to argumentation low if the bondservant permits it. Some disciplinarian crave the falling bend (high→low transition) of the dent baddest to admit an activity such as the Maxim MAX1242 ADC, which starts about-face on said transition. With assorted bondservant devices, an absolute SS arresting is adapted from the adept for anniversary bondservant device.

Most bondservant accessories accept tri-state outputs so their MISO arresting becomes top impedance ("disconnected") if the accessory is not selected. Accessories after tri-state outputs can't allotment SPI bus segments with added devices; alone one such bondservant could allocution to the master, and alone its dent baddest could be activated.

edit Abstracts transmission

A archetypal accouterments bureaucracy application two about-face registers to anatomy an inter-chip annular buffer

To activate a communication, the adept aboriginal configures the clock, application a abundance beneath than or according to the best abundance the bondservant accessory supports. Such frequencies are frequently in the ambit of 1–70 MHz.

The adept again transmits the adapted dent baddest bit for the adapted dent to a argumentation 0. A argumentation 0 is transmitted because the dent baddest band is alive low, acceptation its "off" accompaniment is a argumentation 1; "on" is asserted with a argumentation 0. If a cat-and-mouse aeon is adapted (such as for analog-to-digital conversion), again the adept accept to delay for at atomic that aeon of time afore starting to affair alarm cycles.

During anniversary SPI alarm cycle, a abounding bifold abstracts manual occurs:

the adept sends a bit on the MOSI line; the bondservant reads it from that aforementioned line

the bondservant sends a bit on the MISO line; the adept reads it from that aforementioned line

Not all transmissions crave all four of these operations to be allusive but they do happen.

Transmissions frequently absorb two about-face registers of some accustomed chat size, such as eight bits, one in the adept and one in the slave; they are affiliated in a ring. Abstracts are usually confused out with the a lot of cogent bit first, while alive a new atomic cogent bit into the aforementioned register. After that annals has been confused out, the adept and bondservant accept exchanged annals values. Again anniversary accessory takes that amount and does something with it, such as autograph it to memory. If there are added abstracts to exchange, the about-face registers are loaded with new abstracts and the action repeats.

Transmissions may absorb any amount of alarm cycles. If there are no added abstracts to be transmitted, the adept stops toggling its clock. Normally, it again deselects the slave.

Transmissions generally abide of 8-bit words, and a adept can admit assorted such transmissions if it wishes/needs. However, added chat sizes are aswell common, such as 16-bit words for touchscreen controllers or audio codecs, like the TSC2101 from Texas Instruments; or 12-bit words for abounding digital-to-analog or analog-to-digital converters.

Every bondservant on the bus that hasn't been activated application its dent baddest band accept to apathy the ascribe alarm and MOSI signals, and accept to not drive MISO. The adept accept to baddest alone one bondservant at a time.

edit Alarm polarity and phase

A timing diagram assuming alarm polarity and phase

In accession to ambience the alarm frequency, the adept accept to aswell configure the alarm polarity and appearance with account to the data. Freescale's SPI Block Guide1 names these two options as CPOL and CPHA respectively, and a lot of vendors accept adopted that convention.

The timing diagram is apparent to the right. The timing is added declared beneath and applies to both the adept and the bondservant device.

At CPOL=0 the abject amount of the alarm is zero

For CPHA=0, abstracts are captured on the clock's ascent bend (low→high transition) and abstracts are broadcast on a falling bend (high→low alarm transition).

For CPHA=1, abstracts are captured on the clock's falling bend and abstracts are broadcast on a ascent edge.

At CPOL=1 the abject amount of the alarm is one (inversion of CPOL=0)

For CPHA=0, abstracts are captured on clock's falling bend and abstracts are broadcast on a ascent edge.

For CPHA=1, abstracts are captured on clock's ascent bend and abstracts are broadcast on a falling edge.

That is, CPHA=0 agency sample on the arch (first) alarm edge, while CPHA=1 agency sample on the abaft (second) alarm edge, behindhand of whether that alarm bend is ascent or falling. Agenda that with CPHA=0, the abstracts accept to be abiding for a bisected aeon afore the aboriginal alarm cycle. For all CPOL and CPHA modes, the antecedent alarm amount accept to be abiding afore the dent baddest band goes active.

Also, agenda that "data are read" in this certificate added about agency "data may be read". The MOSI and MISO signals are usually abiding (at their accession points) for the bisected aeon until the next alarm transition. SPI adept and bondservant accessories may able-bodied sample abstracts at altered credibility in that bisected cycle.

This adds added adaptability to the advice approach amid the adept and slave.

Some articles use altered allotment conventions. For example, the TI MSP430 uses the name UCCKPL instead of CPOL, and its UCCKPH is the changed of CPHA. If abutting two chips together, anxiously appraise the alarm appearance initialization ethics to be abiding of application the appropriate settings.

edit Approach numbers

The combinations of polarity and phases are generally referred to as modes which are frequently numbered according to the afterward convention, with CPOL as the top adjustment bit and CPHA as the low adjustment bit:

Mode CPOL CPHA

0 0 0

1 0 1

2 1 0

3 1 1

Another frequently acclimated characters represents the approach as a (CPOL,CPHA) tuple, e.g. the amount '(0,1)' would announce CPOL=0 and CPHA=1

edit Absolute bondservant SPI configuration

Typical SPI bus: adept and three absolute slaves

In the absolute bondservant configuration, there is an absolute dent baddest band for anniversary slave. This is the way SPI is frequently used. Since the MISO pins of the disciplinarian are affiliated together, they are adapted to be tri-state pins.

edit Daisy alternation SPI configuration

Daisy-chained SPI bus: adept and accommodating slaves

Some articles with SPI bus are advised to be able of accepting affiliated in a daisy alternation configuration, the aboriginal bondservant achievement accepting affiliated to the additional bondservant input, etc. The SPI anchorage of anniversary bondservant is advised to forward out during the additional accumulation of alarm pulses an exact archetype of what it accustomed during the aboriginal accumulation of alarm pulses. The accomplished alternation acts as an SPI advice about-face register; daisy chaining is generally done with about-face registers to accommodate a coffer of inputs or outputs through SPI. Such a affection alone requires a individual SS band from the master, rather than a abstracted SS band for anniversary slave.2

Applications (discussed later) that crave a daisy alternation agreement cover SGPIO and JTAG.

edit Valid SPI communications

Some bondservant accessories are advised to avoid any SPI communications in which the amount of alarm pulses is greater than specified. Others don't care, blank added inputs and continuing to about-face the aforementioned achievement bit. It is accepted for altered accessories to use SPI communications with altered lengths, as, for example, if SPI is acclimated to admission the browse alternation of a agenda IC by arising a command chat of one admeasurement (perhaps 32 bits) and again accepting a acknowledgment of a altered admeasurement (perhaps 153 bits, one for anniversary pin in that browse chain).

edit Interrupts

SPI accessories sometimes use addition arresting band to forward an arrest arresting to a host CPU. Examples cover pen-down interrupts from touchscreen sensors, thermal absolute alerts from temperature sensors, alarms issued by absolute time alarm chips, SDIO, and angle jack insertions from the complete codec in a corpuscle phone. Interrupts are not covered by the SPI standard; their acceptance is neither banned nor defined by the standard.

edit Archetype of bit-banging the SPI adept protocol

Below is an archetype of bit-banging the SPI agreement as an SPI adept with CPOL=0, CPHA=0, and eight $.25 per transfer. The archetype is accounting in the C programming language. Because this is CPOL=0 the alarm accept to be pulled low afore the dent baddest is activated. The dent baddest band accept to be activated, which frequently agency accepting toggled low, for the borderline afore the alpha of the transfer, and again deactivated afterwards. A lot of peripherals acquiesce or crave several transfers while the baddest band is low; this accepted ability be alleged several times afore deselecting the chip.

Pros and cons of SPI

Advantages

Full bifold communication

Higher throughput than I²C or SMBus

Complete agreement adaptability for the $.25 transferred

Not bound to 8-bit words

Arbitrary best of bulletin size, content, and purpose

Extremely simple accouterments interfacing

Typically lower ability requirements than I²C or SMBus due to beneath dent (including pullups)

No adjudication or associated abortion modes

Slaves use the master's clock, and don't charge attention oscillators

Slaves don't charge a different abode -- clashing I²C or GPIB or SCSI

Transceivers are not needed

Uses alone four pins on IC packages, and affairs in lath layouts or connectors, abundant beneath than alongside interfaces

At a lot of one "unique" bus arresting per accessory (chip select); all others are shared

Signals are unidirectional acceptance for simple Galvanic isolation

edit Disadvantages

Requires added pins on IC bales than I²C, even in the "3-Wire" variant

No in-band addressing; out-of-band dent baddest signals are appropriate on aggregate buses

No accouterments breeze ascendancy by the bondservant (but the adept can adjournment the next alarm bend to apathetic the alteration rate)

No accouterments bondservant acceptance (the adept could be "talking" to annihilation and not apperceive it)

Supports alone one adept device

No error-checking agreement is defined

Generally decumbent to babble spikes causing adulterated communication

Without a academic standard, acceptance acclimation is not possible

Alone handles abbreviate distances compared to RS-232, RS-485, or CAN-bus

Many absolute variations, authoritative it difficult to acquisition development accoutrement like host adapters that abutment those variations


Applications

The lath absolute acreage accumulation compared to a alongside I/O bus are significant, and accept becoming SPI a solid role in anchored systems. That is accurate for a lot of system-on-a-chip processors, both with college end 32-bit processors such as those appliance ARM, MIPS, or PowerPC and with added microcontrollers such as the AVR, PIC, and MSP430. These chips usually cover SPI controllers able of active in either adept or bondservant mode. In-system programmable AVR controllers (including bare ones) can be programmed appliance an SPI interface.3

Chip or FPGA based designs sometimes use SPI to acquaint amid centralized components; on-chip absolute acreage can be as cher as its on-board cousin.

The full-duplex adequacy makes SPI actual simple and able for alone master/single bondservant applications. Some accessories use the full-duplex approach to apparatus an efficient, abrupt abstracts beck for applications such as agenda audio, agenda arresting processing, or telecommunications channels, but a lot of off-the-shelf chips stick to half-duplex request/response protocols.

SPI is acclimated to allocution to a array of peripherals, such as

Sensors: temperature, pressure, ADC, touchscreens, video bold controllers

Control devices: audio codecs, agenda potentiometers, DAC

Camera lenses: Canon EF lens mount

Communications: Ethernet, USB, USART, CAN, IEEE 802.15.4, IEEE 802.11, handheld video games

Memory: beam and EEPROM

Real-time clocks

LCD displays, sometimes even for managing angel data

Any MMC or SD agenda (including SDIO variant)

For top achievement systems, FPGAs sometimes use SPI to interface as a bondservant to a host, as a adept to sensors, or for beam anamnesis acclimated to bootstrap if they are SRAM-based.

JTAG is about an appliance assemblage for a 3-wire SPI flavor, appliance altered arresting namescitation needed: TCK not SCK, TDI not MOSI, TDO not MISO. It defines a accompaniment apparatus (driven by a TMS arresting instead of a dent baddest line), agreement messages, a amount command set, the adeptness to daisy-chain accessories in a "scan chain", and how vendors ascertain new commands. The accessories in a browse alternation are initially advised as a alone device, and transitions on TMS amend their accompaniment machines; already the alone accessories are identified, commands may be issued that affect alone one accessory in that browse chain. Altered vendors use altered JTAG connectors. Bit strings acclimated in JTAG are generally continued and not multiples of 8 bit words; for example, a abuttals browse letters arresting accompaniment on anniversary of several hundred pins.

SGPIO is about addition (incompatible) appliance assemblage for SPI advised for accurate backplane administration activitiescitation needed. SGPIO uses 3-bit messages.The lath absolute acreage accumulation compared to a alongside I/O bus are significant, and accept becoming SPI a solid role in anchored systems. That is accurate for a lot of system-on-a-chip processors, both with college end 32-bit processors such as those appliance ARM, MIPS, or PowerPC and with added microcontrollers such as the AVR, PIC, and MSP430. These chips usually cover SPI controllers able of active in either adept or bondservant mode. In-system programmable AVR controllers (including bare ones) can be programmed appliance an SPI interface.3

Chip or FPGA based designs sometimes use SPI to acquaint amid centralized components; on-chip absolute acreage can be as cher as its on-board cousin.

The full-duplex adequacy makes SPI actual simple and able for alone master/single bondservant applications. Some accessories use the full-duplex approach to apparatus an efficient, abrupt abstracts beck for applications such as agenda audio, agenda arresting processing, or telecommunications channels, but a lot of off-the-shelf chips stick to half-duplex request/response protocols.

SPI is acclimated to allocution to a array of peripherals, such as

Sensors: temperature, pressure, ADC, touchscreens, video bold controllers

Control devices: audio codecs, agenda potentiometers, DAC

Camera lenses: Canon EF lens mount

Communications: Ethernet, USB, USART, CAN, IEEE 802.15.4, IEEE 802.11, handheld video games

Memory: beam and EEPROM

Real-time clocks

LCD displays, sometimes even for managing angel data

Any MMC or SD agenda (including SDIO variant)

For top achievement systems, FPGAs sometimes use SPI to interface as a bondservant to a host, as a adept to sensors, or for beam anamnesis acclimated to bootstrap if they are SRAM-based.

JTAG is about an appliance assemblage for a 3-wire SPI flavor, appliance altered arresting namescitation needed: TCK not SCK, TDI not MOSI, TDO not MISO. It defines a accompaniment apparatus (driven by a TMS arresting instead of a dent baddest line), agreement messages, a amount command set, the adeptness to daisy-chain accessories in a "scan chain", and how vendors ascertain new commands. The accessories in a browse alternation are initially advised as a alone device, and transitions on TMS amend their accompaniment machines; already the alone accessories are identified, commands may be issued that affect alone one accessory in that browse chain. Altered vendors use altered JTAG connectors. Bit strings acclimated in JTAG are generally continued and not multiples of 8 bit words; for example, a abuttals browse letters arresting accompaniment on anniversary of several hundred pins.

SGPIO is about addition (incompatible) appliance assemblage for SPI advised for accurate backplane administration activitiescitation needed. SGPIO uses 3-bit messages.

Standards

The SPI bus is a de facto standard. However, the abridgement of a academic accepted is reflected in a advanced array of agreement options. Different chat sizes are common. Every accessory defines its own protocol, including whether or not it supports commands at all. Some accessories are transmit-only; others are receive-only. Dent selects are sometimes active-high rather than active-low. Some protocols forward the atomic cogent bit first.

Some accessories even accept accessory variances from the CPOL/CPHA modes declared above. Sending abstracts from bondservant to adept may use the adverse alarm bend as adept to slave. Accessories generally crave added alarm abandoned time afore the aboriginal alarm or afterwards the endure one, or amid a command and its response. Some accessories accept two clocks, one to "capture" or "display" data, and addition to alarm it into the device. Many of these "capture clocks" run from the dent baddest line.

Some accessories crave an added breeze ascendancy arresting from bondservant to master, advertence if abstracts are ready. This leads to a "five wire" agreement instead of the accepted four. Such a "ready" or "enable" arresting is generally active-low, and needs to be enabled at key credibility such as afterwards commands or amid words. Without such a signal, abstracts alteration ante may charge to be slowed down significantly, or protocols may charge to accept "dummy bytes" inserted, to board the affliction case for the bondservant acknowledgment time. Examples cover initiating an ADC conversion, acclamation the appropriate page of beam memory, and processing abundant of a command that accessory firmware can amount the aboriginal chat of the response. (Many SPI masters don't abutment that arresting directly, and instead await on anchored delays.)

Many SPI chips alone abutment letters that are multiples of 8 bits. Such chips can not interoperate with the JTAG or SGPIO protocols, or any added agreement that requires letters that are not multiples of 8 bits.

There are even hardware-level differences. Some chips amalgamate MOSI and MISO into a individual abstracts band (SI/SO); this is sometimes alleged "3-Wire" signaling (in adverse to accustomed "4-wire" SPI). Addition SPI acidity removes the dent baddest line, managing agreement accompaniment apparatus entry/exit application added methods; this isn't usually alleged 3-Wire though. Anyone defective an alien adapter for SPI defines their own -- UEXT, JTAG connector, Secure Digital agenda socket, etc. . Arresting levels depend absolutely on the chips involved.

Development tools

When developing or troubleshooting systems application SPI, afterimage at the akin of accouterments signals can be important.

edit Host adapters

There are a amount of USB accouterments solutions to accommodate computers, active Linux, Mac, or Windows, SPI adept and/or bondservant capabilities. Many of them aswell accommodate scripting and/or programming capabilities (Visual Basic, C/C++, ...).

A SPI Host Adapter lets the user play the role of a adept on a SPI bus anon from PC. They are acclimated for anchored system, dent (FPGA/ASIC/SoC) and borderline testing, programming and debug.

The key ambit of SPI Adapters are: the best accurate abundance for the consecutive interface, command-to-command cessation and the best breadth for SPI commands. It is accessible to acquisition SPI Adapters on the bazaar today that abutment up to 100 MHz consecutive interfaces, with around absolute admission length.

SPI agreement getting a de facto standard, some 'SPI Host Adapters' aswell accept the adeptness of acknowledging added protocols above the 'traditional 4-wires' SPI (e.g: abutment of quad-SPI agreement or added custom consecutive agreement that acquire from SPI4).

edit Agreement analyzers

SPI Agreement Analyzers are accoutrement which sample a SPI bus and break the electrical signals to accommodate a higher-level appearance of the abstracts getting transmitted on a specific bus.

edit Oscilloscopes

Every above oscilloscope bell-ringer offers oscilloscope-based triggering and agreement adaptation for SPI{citation required}. Most abutment 2-, 3-, and 4-wire SPI{citation required}. The triggering and adaptation adequacy is about offered as an alternative extra{citation required}. SPI signals can be accessed via analog oscilloscope channels or with agenda MSO channels{citation required}.

edit Argumentation analyzers

When developing and/or troubleshooting the SPI bus, assay of accouterments signals can be actual important. Argumentation analyzers are accoutrement which collect, analyze, decode, abundance signals so humans can appearance the accelerated waveforms at their leisure. Argumentation analyzers affectation time-stamps of anniversary arresting akin change, which can advice acquisition agreement problems. Most argumentation analyzers accept the adequacy to break bus signals into high-level agreement abstracts and appearance ASCII data.

Related terms

Queued consecutive borderline interface (QSPI) and Multichannel buffered consecutive anchorage (MCBSP)

The queued consecutive borderline interface (QSPI) is one blazon of SPI controller, not addition bus type. It uses a abstracts chain with programmable chain pointers acceptance some abstracts transfers after CPU intervention.5 It aswell has a wrap-around approach acceptance connected transfers to and from the chain with no CPU intervention. As a result, the peripherals arise to the CPU as memory-mapped alongside devices. This affection is advantageous in applications such as ascendancy of an A/D converter. Added programmable appearance in QSPI are dent selects and alteration length/delay.

SPI controllers from altered vendors abutment altered affection sets; such DMA queues are not uncommon, although they may be associated with abstracted DMA engines rather than the SPI ambassador itself (MCBSP).6 A lot of SPI adept controllers accommodate abutment for up to four dent selects,7 although some crave dent selects to be managed alone through GPIO lines.

edit Microwire

Microwire is about a antecedent of SPI. It's a austere subset: bisected duplex, and application SPI approach 0. (Microwire-Plus supports added SPI modes.) Microwire chips tend to charge slower alarm ante than newer SPI versions; conceivably 2 MHz vs. 20 MHz. Some Microwire chips aswell abutment a 3-Wire approach (see below), which fits neatly with the brake to bisected duplex.

edit 3-wire consecutive buses

As mentioned above, one alternative of SPI uses individual bidirectional abstracts band (Slave Out/Slave IN, alleged SISO) instead of two unidirectional ones (MOSI and MISO). Clearly, this alternative is belted to a bisected bifold mode. It tends to be acclimated for lower achievement parts, such as baby EEPROMs acclimated alone during arrangement startup and assertive sensors, and Microwire. As of this writing, few SPI adept controllers abutment this mode; although it can generally be calmly bit-banged in software.

When anyone says a allotment supports SPI or Microwire, you can commonly accept that agency the four-wire version.

However, if anyone talks about a allotment acknowledging a 3-wire consecutive bus you should consistently acquisition out what it means: accepted 4-wire SPI, after the dent baddest pin from that count, back a lot of buses use dent selects but alone three affairs backpack "real" signals; (More, sometimes with an distinct SPI bus articulation the device's dent baddest will be hard-wired as "always selected".) "real" 3-wire SPI; or even a RS232 cable with RXD, TXD, and shield/ground, or an application-specific signaling scheme.

edit Multi I/O SPI

As against to 3-wire consecutive buses, multi I/O SPI uses assorted alongside abstracts curve (e.g. IO0 to IO3) to access throughput. Dual I/O SPI application two abstracts curve has commensurable throughput to fast individual I/O (MISO/MOSI). Quad I/O SPI application four abstracts curve has about bifold the throughput.8 Multi I/O SPI accessories tend to be bisected bifold agnate to 3-Wire accessories to abstain abacus too abounding pins. These consecutive anamnesis accessories amalgamate the advantage of added acceleration with bargain pin calculation as compared to alongside memory.