Concept Flow - Clock polarity and phase (CPOL, CPHA)
Start SPI Clock Cycle
Check CPOL
Check CPHA
Data transfer
End SPI Clock Cycle
This flow shows how CPOL sets clock idle level and CPHA sets when data is sampled during SPI communication.
/* SPI clock example */ int CPOL = 0; // Clock idle low int CPHA = 1; // Sample on trailing edge // Simulate one clock cycle if (CPOL == 0) { // Clock starts low } if (CPHA == 1) { // Sample data on trailing edge }
| Step | CPOL | CPHA | Clock Idle Level | Sample Edge | Action |
|---|---|---|---|---|---|
| 1 | 0 | 1 | Low | Trailing edge | Start clock cycle with clock low |
| 2 | 0 | 1 | Low | Trailing edge | Data setup on leading edge (rising) |
| 3 | 0 | 1 | Low | Trailing edge | Sample data on trailing edge (falling) |
| 4 | 0 | 1 | Low | Trailing edge | End clock cycle |
| 5 | 1 | 0 | High | Leading edge | Start clock cycle with clock high |
| 6 | 1 | 0 | High | Leading edge | Sample data on leading edge (rising) |
| 7 | 1 | 0 | High | Leading edge | Data setup on trailing edge (falling) |
| 8 | 1 | 0 | High | Leading edge | End clock cycle |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 | After Step 4 | After Step 5 | After Step 6 | After Step 7 | After Step 8 |
|---|---|---|---|---|---|---|---|---|---|
| CPOL | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| CPHA | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Clock Level | Undefined | Low | Rising edge | Falling edge | Low | High | Rising edge | Falling edge | High |
| Sample Edge | Undefined | Trailing | Trailing | Trailing | Trailing | Leading | Leading | Leading | Leading |
SPI clock uses CPOL and CPHA to control timing. CPOL sets clock idle level: 0=low, 1=high. CPHA sets data sampling edge: 0=leading, 1=trailing. Together they define when data is stable and sampled. Correct settings ensure reliable SPI communication.