address SPI_CLKDIV_PRE requirements
* respect N-1 * avoid range overflow
This commit is contained in:
parent
ac50f9c6a5
commit
4cf5f37450
|
@ -116,6 +116,9 @@ void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, unsigned databi
|
|||
clock_div += 0x02;
|
||||
}
|
||||
clock_div >>= 1;
|
||||
// clip to maximum possible CLKDIV_PRE
|
||||
clock_div = clock_div > SPI_CLKDIV_PRE ? SPI_CLKDIV_PRE : clock_div - 1;
|
||||
|
||||
WRITE_PERI_REG(SPI_CLOCK(spi_no),
|
||||
((clock_div&SPI_CLKDIV_PRE)<<SPI_CLKDIV_PRE_S)|
|
||||
((1&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
|
||||
|
|
Loading…
Reference in New Issue