Skip to content

Commit b85880a

Browse files
committed
esp32/machine_i2c.c: Fix default I2C pins for new ESP32 C3 and S3.
This addresses issue micropython#17103. The default I2C init does not require setting SCL or SDA but the default pins for C3 (and S3?) conflict with the espressif GPIO usage. For the C3, pins 18/19 are for USB/JTAG. If used for I2C() they will cause the REPL to hang on initialization of the I2C. For the S3 pin 19 is allocated for USB/JTAG also but the defaults do not seem to affect the REPL. Also the default pins for I2C(2) were 25/26 which are invalid for S3. This pull request updates pin settings for C3 and S3 I2C defaults if not specified during the build. See PR micropython#16956 See Issue micropython#17103 Signed-off-by: Rick Sorensen <[email protected]>
1 parent 076d9ad commit b85880a

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ports/esp32/machine_i2c.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,27 @@
3535
#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C
3636

3737
#ifndef MICROPY_HW_I2C0_SCL
38-
#if CONFIG_IDF_TARGET_ESP32
39-
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_18)
40-
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_19)
41-
#else
38+
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
4239
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_9)
4340
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_8)
41+
#else
42+
#define MICROPY_HW_I2C0_SCL (GPIO_NUM_18)
43+
#define MICROPY_HW_I2C0_SDA (GPIO_NUM_19)
4444
#endif
4545
#endif
4646

4747
#ifndef MICROPY_HW_I2C1_SCL
48-
#if CONFIG_IDF_TARGET_ESP32
48+
49+
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3
50+
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_15)
51+
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_16)
52+
#else
4953
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_25)
5054
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_26)
51-
#else
52-
#define MICROPY_HW_I2C1_SCL (GPIO_NUM_9)
53-
#define MICROPY_HW_I2C1_SDA (GPIO_NUM_8)
5455
#endif
5556
#endif
5657

58+
5759
#if SOC_I2C_SUPPORT_XTAL
5860
#define I2C_SCLK_FREQ XTAL_CLK_FREQ
5961
#elif SOC_I2C_SUPPORT_APB
@@ -187,7 +189,8 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_
187189
if (self->port == I2C_NUM_0) {
188190
self->scl = MICROPY_HW_I2C0_SCL;
189191
self->sda = MICROPY_HW_I2C0_SDA;
190-
} else {
192+
}
193+
else {
191194
self->scl = MICROPY_HW_I2C1_SCL;
192195
self->sda = MICROPY_HW_I2C1_SDA;
193196
}

0 commit comments

Comments
 (0)