From a05e40bfe39eaed2f1492b9fd3ad0aa739ba4dce Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Fri, 26 Jan 2024 11:12:25 +0100 Subject: [PATCH] fix(lp_i2c): Fixed an issue where the LP_I2C IO lines were not in open-drain mode This commit fixes an issue where in the LP I2C IO lines were not initialized in open-drain mode. Closes https://github.com/espressif/esp-idf/issues/12969 --- components/ulp/lp_core/lp_core_i2c.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/ulp/lp_core/lp_core_i2c.c b/components/ulp/lp_core/lp_core_i2c.c index 5acde94ece1..58d74eb9ee1 100644 --- a/components/ulp/lp_core/lp_core_i2c.c +++ b/components/ulp/lp_core/lp_core_i2c.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -47,8 +47,9 @@ static esp_err_t lp_i2c_configure_io(gpio_num_t io_num, bool pullup_en) { /* Initialize IO Pin */ ESP_RETURN_ON_ERROR(rtc_gpio_init(io_num), LPI2C_TAG, "LP GPIO Init failed for GPIO %d", io_num); - /* Set direction to input+output */ - ESP_RETURN_ON_ERROR(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_OUTPUT), LPI2C_TAG, "LP GPIO Set direction failed for %d", io_num); + + /* Set direction to input+output open-drain mode */ + ESP_RETURN_ON_ERROR(rtc_gpio_set_direction(io_num, RTC_GPIO_MODE_INPUT_OUTPUT_OD), LPI2C_TAG, "LP GPIO Set direction failed for %d", io_num); /* Disable pulldown on the io pin */ ESP_RETURN_ON_ERROR(rtc_gpio_pulldown_dis(io_num), LPI2C_TAG, "LP GPIO pulldown disable failed for %d", io_num); /* Enable pullup based on pullup_en flag */ @@ -143,6 +144,10 @@ esp_err_t lp_core_i2c_master_init(i2c_port_t lp_i2c_num, const lp_core_i2c_cfg_t /* Initialize LP I2C Master mode */ i2c_hal_master_init(&i2c_hal); + /* Enable internal open-drain mode for I2C IO lines */ + i2c_hal.dev->ctr.sda_force_out = 0; + i2c_hal.dev->ctr.scl_force_out = 0; + /* Configure LP I2C clock and timing paramters */ ESP_RETURN_ON_ERROR(lp_i2c_config_clk(cfg), LPI2C_TAG, "Failed to configure LP I2C source clock");