Skip to content

Commit 6b703ea

Browse files
authored
Merge pull request #7963 from dhalbert/esp-spi-baudrate
Report SPI frequency accurately on Espressif
2 parents c75a768 + d99b063 commit 6b703ea

File tree

1 file changed

+4
-2
lines changed
  • ports/espressif/common-hal/busio

1 file changed

+4
-2
lines changed

ports/espressif/common-hal/busio/SPI.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ void spi_reset(void) {
5656

5757
static void set_spi_config(busio_spi_obj_t *self,
5858
uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) {
59+
// 128 is a 50% duty cycle.
60+
const int closest_clock = spi_get_actual_clock(APB_CLK_FREQ, baudrate, 128);
5961
const spi_device_interface_config_t device_config = {
60-
.clock_speed_hz = baudrate,
62+
.clock_speed_hz = closest_clock,
6163
.mode = phase | (polarity << 1),
6264
.spics_io_num = -1, // No CS pin
6365
.queue_size = MAX_SPI_TRANSACTIONS,
@@ -67,7 +69,7 @@ static void set_spi_config(busio_spi_obj_t *self,
6769
if (result != ESP_OK) {
6870
mp_raise_RuntimeError(translate("SPI configuration failed"));
6971
}
70-
self->baudrate = baudrate;
72+
self->baudrate = closest_clock;
7173
self->polarity = polarity;
7274
self->phase = phase;
7375
self->bits = bits;

0 commit comments

Comments
 (0)