The Byzantine
The Byzantine

Reputation: 619

The use of CPOL/CPHA settings in SPI communication

Could any one please give me real life examples where the 4 modes of CPOL/CPHA configuration in SPI communication are useful? I understand how they work but fail to know when to use them. I have read some refer shortly for compatibility purposes due to non-standard implementations, how is this so?

Thanks

Upvotes: 2

Views: 12872

Answers (3)

Code Painters
Code Painters

Reputation: 7275

Let me try to address the question why there are 4 modes introduced. I can't provide any hard evidence, yet I believe this is a possible explanation:

First of all - SPI is pretty simple, it's all about sending some stream of bits serially, with separate clock and data lines, the SPI mode controls the clock polarity and phase. Given the simplicity of SPI, all you need to, for example, implement SPI slave device is a serial-in shift register, like 74HC595 (see a sample application).

Now, while SPI device manufacturers could obviously have agreed upon one mode used universally, I believe that additional modes were introduced to make it simple to interface with simple shift registers. There are many available, with various requirements regarding clock polarity/phase - SPI modes make it easier to connect them without any glue logic.

Upvotes: 2

Venkat Ram
Venkat Ram

Reputation: 73

SPI interface allows to transmit and receive data simultaneously on two lines (MOSI and MISO). Clock polarity (CPOL) and clock phase (CPHA) are the main parameters that define a clock format to be used by the SPI bus. Depending on CPOL parameter, SPI clock may be inverted or non-inverted. CPHA parameter is used to shift the sampling phase. If CPHA=0 the data are sampled on the leading (first) clock edge. If CPHA=1 the data are sampled on the trailing (second) clock edge, regardless of whether that clock edge is rising or falling.

Upvotes: 9

kkrambo
kkrambo

Reputation: 7057

I have a board that uses SPI to interface to an Flash memory, a real time clock, and an accelerometer. The data sheets for these devices each specify different settings for CPOL/CPHA. So when the microcontroller opens the SPI interface to a particular device, it configures the SPI controller appropriately for that device. I don't think there is anything significant about the four different modes. You just need to use the mode that is specified by the device that you intend to interface with. Some devices may work in more than one mode. In that case, use whichever mode is convenient.

Upvotes: 2

Related Questions