Among the most common—and simplest—serial interfaces supported by built-in CPU peripherals is Serial Peripheral Interface (SPI). Four hardware signals connect a defined master (or host) to each slave (or device): a slave select, a clock, a slave input and a slave output. Three of these, all except the slave select, may be shared among all slaves, though hosts often have several SPI controllers to simplify integration and allow simultaneous access to multiple slaves. Serial flash, serial EEPROM and SD/MMC cards are among the many devices which use SPI.
Signal | Description |
| Slave select |
| Clock |
| Slave output (master input) |
| Slave input (master output) |
Table C-3 SPI signals
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}.
- If CPOL = 0, the clock is low when inactive.
Slave select polarity. The “active” level of the slave select may be electrically high or low. Low is ubiquitous, high rare.
...