Fixed an issue that caused incorrect settings when the SPI clock was less than 244141Hz. (#1633)

This commit is contained in:
aizaki77 2024-06-27 23:28:46 +09:00 committed by GitHub
parent f5b7a9135b
commit 8b0146c142
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,7 +51,7 @@ uint spi_set_baudrate(spi_inst_t *spi, uint baudrate) {
// Find smallest prescale value which puts output frequency in range of
// post-divide. Prescale is an even number from 2 to 254 inclusive.
for (prescale = 2; prescale <= 254; prescale += 2) {
if (freq_in < (prescale + 2) * 256 * (uint64_t) baudrate)
if (freq_in < prescale * 256 * (uint64_t) baudrate)
break;
}
invalid_params_if(SPI, prescale > 254); // Frequency too low