Skip to content

Commit 2523fee

Browse files
committed
fix(i2c): Fix the potential wdt might happen after nack,
Closes #17720
1 parent 6b40ac6 commit 2523fee

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

components/esp_driver_i2c/i2c_master.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,15 @@ static void s_i2c_send_commands(i2c_master_bus_handle_t i2c_master, TickType_t t
590590
// For i2c nack detected, the i2c transaction not finish.
591591
// start->address->nack->stop
592592
// So wait the whole transaction finishes, then quit the function.
593+
TickType_t start_tick = xTaskGetTickCount();
594+
const TickType_t timeout_ticks = ticks_to_wait;
593595
while (i2c_ll_is_bus_busy(hal->dev)) {
594-
__asm__ __volatile__("nop");
596+
if ((xTaskGetTickCount() - start_tick) > timeout_ticks) {
597+
ESP_LOGE(TAG, "I2C bus is still busy but software timeout detected");
598+
atomic_store(&i2c_master->status, I2C_STATUS_TIMEOUT);
599+
s_i2c_hw_fsm_reset(i2c_master, true);
600+
break;
601+
}
595602
}
596603
}
597604
s_i2c_err_log_print(event, i2c_master->bypass_nack_log);

0 commit comments

Comments
 (0)