From 5b46ef3cdd66ccae641ba7649c2edf064811b341 Mon Sep 17 00:00:00 2001 From: Sudeep Mohanty Date: Mon, 7 Aug 2023 09:59:28 +0200 Subject: [PATCH] fix(lp_i2c): Fixed a bug where LP I2C write got stuck This commit fixes a bug where an I2C write got stuck when using the lp_core_i2c_master_write_read_device() API. This was because the LP I2C HW was not programmed with an END condition and therefore did not know the end of a transaction. Closes: https://github.com/espressif/esp-idf/issues/11958 --- components/ulp/lp_core/lp_core/lp_core_i2c.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/ulp/lp_core/lp_core/lp_core_i2c.c b/components/ulp/lp_core/lp_core/lp_core_i2c.c index feccabc5b195..7b73fc1cc23f 100644 --- a/components/ulp/lp_core/lp_core/lp_core_i2c.c +++ b/components/ulp/lp_core/lp_core/lp_core_i2c.c @@ -382,11 +382,9 @@ esp_err_t lp_core_i2c_master_write_read_device(i2c_port_t lp_i2c_num, uint16_t d i2c_ll_write_txfifo(dev, &data_wr[data_idx], fifo_size); lp_core_i2c_format_cmd(cmd_idx++, I2C_LL_CMD_WRITE, 0, LP_I2C_ACK, s_ack_check_en, fifo_size); - if (remaining_bytes) { - /* This means we have to send more than what can fit in the Tx FIFO. Insert an End command. */ - lp_core_i2c_format_cmd(cmd_idx++, I2C_LL_CMD_END, 0, 0, 0, 0); - cmd_idx = 0; - } + /* Insert an End command to signal the end of the write transaction to the HW */ + lp_core_i2c_format_cmd(cmd_idx++, I2C_LL_CMD_END, 0, 0, 0, 0); + cmd_idx = 0; /* Initiate I2C transfer */ i2c_ll_update(dev);