File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed
ports/espressif/common-hal/busio Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -56,8 +56,10 @@ void spi_reset(void) {
56
56
57
57
static void set_spi_config (busio_spi_obj_t * self ,
58
58
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 );
59
61
const spi_device_interface_config_t device_config = {
60
- .clock_speed_hz = baudrate ,
62
+ .clock_speed_hz = closest_clock ,
61
63
.mode = phase | (polarity << 1 ),
62
64
.spics_io_num = -1 , // No CS pin
63
65
.queue_size = MAX_SPI_TRANSACTIONS ,
@@ -67,7 +69,7 @@ static void set_spi_config(busio_spi_obj_t *self,
67
69
if (result != ESP_OK ) {
68
70
mp_raise_RuntimeError (translate ("SPI configuration failed" ));
69
71
}
70
- self -> baudrate = baudrate ;
72
+ self -> baudrate = closest_clock ;
71
73
self -> polarity = polarity ;
72
74
self -> phase = phase ;
73
75
self -> bits = bits ;
You can’t perform that action at this time.
0 commit comments