Saturday, February 11, 2012

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.

No comments:

Post a Comment