From 467356cfcd24b56abe00760413faea2a837885e5 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Wed, 4 Jan 2023 12:12:47 +0800 Subject: [PATCH 1/2] I2C: Fix issue that pointer would be NULL if calls i2c_param first, Closes https://github.com/espressif/esp-idf/issues/10163 --- components/driver/i2c.c | 1 + components/hal/i2c_hal.c | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/driver/i2c.c b/components/driver/i2c.c index 0c2411acbb..127a67f124 100644 --- a/components/driver/i2c.c +++ b/components/driver/i2c.c @@ -756,6 +756,7 @@ esp_err_t i2c_param_config(i2c_port_t i2c_num, const i2c_config_t *i2c_conf) return ret; } i2c_hw_enable(i2c_num); + i2c_hal_init(&i2c_context[i2c_num].hal, i2c_num); I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock)); i2c_ll_disable_intr_mask(i2c_context[i2c_num].hal.dev, I2C_LL_INTR_MASK); i2c_ll_clear_intr_mask(i2c_context[i2c_num].hal.dev, I2C_LL_INTR_MASK); diff --git a/components/hal/i2c_hal.c b/components/hal/i2c_hal.c index 567586ff93..efb55e94c2 100644 --- a/components/hal/i2c_hal.c +++ b/components/hal/i2c_hal.c @@ -51,8 +51,10 @@ void i2c_hal_master_init(i2c_hal_context_t *hal) void i2c_hal_init(i2c_hal_context_t *hal, int i2c_port) { - hal->dev = I2C_LL_GET_HW(i2c_port); - i2c_ll_enable_controller_clock(hal->dev, true); + if (hal->dev == NULL) { + hal->dev = I2C_LL_GET_HW(i2c_port); + i2c_ll_enable_controller_clock(hal->dev, true); + } } void i2c_hal_deinit(i2c_hal_context_t *hal) From dfa78f244e1f0e6403c789ff5253a520ce996d24 Mon Sep 17 00:00:00 2001 From: Cao Sen Miao Date: Wed, 4 Jan 2023 12:28:20 +0800 Subject: [PATCH 2/2] I2C: Fix doc about pull-up, Closes https://github.com/espressif/esp-idf/issues/9791 --- examples/peripherals/i2c/i2c_tools/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/peripherals/i2c/i2c_tools/README.md b/examples/peripherals/i2c/i2c_tools/README.md index effb1382f3..cac922ee77 100644 --- a/examples/peripherals/i2c/i2c_tools/README.md +++ b/examples/peripherals/i2c/i2c_tools/README.md @@ -37,7 +37,7 @@ To run this example, you should have any ESP32, ESP32-S and ESP32-C based develo | ESP32-H4 I2C Master | GPIO5 | GPIO6 | GND | GND | 3.3V | | Sensor | SDA | SCL | GND | WAK | VCC | -**Note: ** There’s no need to add an external pull-up resistors for SDA/SCL pin, because the driver will enable the internal pull-up resistors itself. +**Note:** It is recommended to add external pull-up resistors for SDA/SCL pins to make the communication more stable, though the driver will enable internal pull-up resistors. ### Configure the project