From 8b0146c142cab3028fe2a2ebbc87196c4d2e087f Mon Sep 17 00:00:00 2001 From: aizaki77 <156364565+aizaki77@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:28:46 +0900 Subject: [PATCH] Fixed an issue that caused incorrect settings when the SPI clock was less than 244141Hz. (#1633) --- src/rp2_common/hardware_spi/spi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_spi/spi.c b/src/rp2_common/hardware_spi/spi.c index 035a710e..d20c1dcc 100644 --- a/src/rp2_common/hardware_spi/spi.c +++ b/src/rp2_common/hardware_spi/spi.c @@ -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