File tree Expand file tree Collapse file tree
ports/espressif/common-hal/busio Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,8 +56,10 @@ void spi_reset(void) {
5656
5757static 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 ;
You can’t perform that action at this time.
0 commit comments