From 71ba035dcc6f13f8b30f268e0847de878f2caac8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 8 Jan 2025 16:39:49 -0500 Subject: [PATCH] ports/espressif/common-hal/busio/I2C.c: add delay after probe for ESP32-S2 --- ports/espressif/common-hal/busio/I2C.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ports/espressif/common-hal/busio/I2C.c b/ports/espressif/common-hal/busio/I2C.c index 88dffb5d2c82..98c453ba3c08 100644 --- a/ports/espressif/common-hal/busio/I2C.c +++ b/ports/espressif/common-hal/busio/I2C.c @@ -6,6 +6,7 @@ #include "shared-bindings/busio/I2C.h" #include "py/mperrno.h" +#include "py/mphal.h" #include "py/runtime.h" #include "components/driver/i2c/include/driver/i2c.h" @@ -134,6 +135,12 @@ void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { esp_err_t result = i2c_master_probe(self->handle, addr, 10); + + #if defined(CONFIG_IDF_TARGET_ESP32S2) + // ESP32-S2 gives spurious results when probe is called multiple times in succession without this delay. + mp_hal_delay_ms(1); + #endif + return result == ESP_OK; }