procedure SPIx_Init_Advanced(..., data_sample, clock_idle, edge: word);
SPI Mode | CPOL | CPHA |
---|---|---|
0 (or 0,0) | 0 | 0 |
1 (or 0,1) | 0 | 1 |
2 (or 1,0) | 1 | 0 |
3 (or 1,1) | 1 | 1 |
SPI Mode | CKP | CKE |
---|---|---|
0 (or 0,0) | 0 | 1 |
1 (or 0,1) | 0 | 0 |
2 (or 1,0) | 1 | 1 |
3 (or 1,1) | 1 | 0 |
procedure Set_SPI_mode(CPOL_, CPHA_: byte); // The 2 paremeters are: // CPOL: SPI clock polarity: 0 = Clock Idle LOW; 1 = Clock Idle HIGH // CPHA: SPI clock Phase: 0 = Transmit edge active to idle; 1 = Transmit edge Idle to active begin CKP_bit := CPOL_; CKE_bit := (CPHA_ xor 1) and 1; // invert bit zero end;Above routine can e.g. used after a usage of an mE SPIx_Init... routine to (re)set the SPI mode.
SPI MODE | clock idle parameter | Edge parameter = the "Sampling" edge |
---|---|---|
0,0 | _SPI_CLK_IDLE_LOW | _SPI_LOW_2_HIGH (pic) _SPI_IDLE_2_ACTIVE (dsPIC) |
0,1 | _SPI_CLK_IDLE_LOW | _SPI_HIGH_2_LOW (pic) _SPI_ACTIVE_TO_IDLE (dsPIC) |
1,0 | _SPI_CLK_IDLE_HIGH | _SPI_HIGH_2_LOW (pic) _SPI_IDLE_TO_ACTIVE (dsPIC) |
1,1 | _SPI_CLK_IDLE_HIGH | _SPI_LOW_2_HIGH (pic) _SPI_ACTIVE_TO_IDLE (dsPIC) |