CircuitPython version
Adafruit CircuitPython 8.0.0-beta.6
Code/REPL
import displayio
import board
import busio
displayio.release_displays()
FREQ = 80_000_000
spi = board.SPI()
spi.try_lock()
spi.configure(baudrate=FREQ)
spi.unlock()
Behavior
The frequency returned will always be what the baudrate parameter was, even if the bus could not be set to that frequency.
Description
spi.frequency always returns the value it was set to, even if that value was not achieved.
From set_spi_config in /ports/espressif/common-hal/busio/SPI.c
...
esp_err_t result = spi_bus_add_device(self->host_id, &device_config, &spi_handle[self->host_id]);
if (result != ESP_OK) {
mp_raise_RuntimeError(translate("SPI configuration failed"));
}
self->baudrate = baudrate;
...
Instead of setting the baudrate calling spi_device_get_actual_freq function could be used to calculate the actual frequency the bus was set to.
Additional information
No response
CircuitPython version
Code/REPL
Behavior
The frequency returned will always be what the
baudrateparameter was, even if the bus could not be set to that frequency.Description
spi.frequencyalways returns the value it was set to, even if that value was not achieved.From
set_spi_configin /ports/espressif/common-hal/busio/SPI.c... esp_err_t result = spi_bus_add_device(self->host_id, &device_config, &spi_handle[self->host_id]); if (result != ESP_OK) { mp_raise_RuntimeError(translate("SPI configuration failed")); } self->baudrate = baudrate; ...Instead of setting the baudrate calling
spi_device_get_actual_freqfunction could be used to calculate the actual frequency the bus was set to.Additional information
No response