Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

No specification exists for SPI, a condition which invites technological divergence. So though the simplicity of the interface limits variations between implementations, the required transfer unit length, shift direction, clock frequency and clock polarity and phase do vary from device to device. Take as an example Figure C-3 which gives the bit form of a basic command/response exchange on a typical serial flash. The command and response both divide into 8-bit chunks, the transfer unit for the device. Within these units, the data is transferred from most significant bit (MSB) to least significant bit (LSB), which is the slave’s shift direction. Though not evident from the diagram—the horizontal axis being labeled in clocks rather than time—the slave cannot operate at a frequency higher than 20-MHz. Finally, the clock signal prior to slave select activation is low (clock polarity or CPOL is 0), and data is latched on the rising clock edge (clock phase or CPHA is 0). Together, those are the aspects of SPI communication that may need to be configured:

  • Transfer unit length. A transfer unit is the underlying unit of commands, responses and data. The most common value is eight bits, though slaves commonly require (and masters commonly support) between 8 and 16 bits.
  • Shift direction. Either the MSB or LSB of each transfer unit can be the first transmitted on the data line.
  • Clock frequency. Limits are usually imposed upon the frequency of the clock signal. Of all variable SPI communication parameters, only this one is explicitly set by the device driver.
  • Clock polarity and phase (CPOL and CPHA). SPI communication takes place in any of four modes, depending on the clock phase and clock polarity settings:
    • If CPOL = 0, the clock is low when inactive.

      If CPOL = 1, the clock is high when inactive.

    • If CPHA = 0, data is “read” on the leading edge of the clock and “changed” on the following edge.

      If CPHA = 1, data is “changed” on the leading edge of the clock and “read” on the leading edge.

    The most commonly-supported settings are {CPOL, CPHA} = {0, 0} and {1, 1}.

  • Slave select polarity. The “active” level of the slave select may be electrically high or low. Low is ubiquitous, high rare.

A BSP is required that abstracts a CPU’s SPI peripheral. The port includes one code file named according to the following rubric:

...

The first argument of each of these port functions is the device unit number, an identifier unique to each driver/device type—after all, it is the number in the device name. For example, “sd:0:” and “nor:0:” both have unit number 1. If two SPI devices are located on the same SPI bus, either of two approaches can resolve unit number conflicts:

  • Unique unit numbers. All devices on the same bus can use the same SPI BSP if and only if each device has a unique unit number. For example, the SD/MMC card “sd:0:” and serial NOR “nor:1:” require only one BSP.
  • Unique SPI BSPs. Devices of different types (e.g., a SD/MMC card and a serial NOR) can have the same unit number if and only if each device uses a separate BSP. For example, the SD/MMC card “sd:0:” and serial “nor:0:” require separate BSPs.