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)