Skip to content

Commit

Permalink
i2c.c: Fix issue espressif#4999 (#5)
Browse files Browse the repository at this point in the history
Fix problem that i2c_master_cmd_begin() waits longer (at least 1 second) than specified in ticks_to_wait, in case the bus is stuck.
  • Loading branch information
KlausPopp committed May 18, 2022
1 parent 40b57d9 commit 6fcb9a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/driver/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,11 +1452,13 @@ esp_err_t i2c_master_cmd_begin(i2c_port_t i2c_num, i2c_cmd_handle_t cmd_handle,
i2c_cmd_evt_t evt;
while (1) {
TickType_t wait_time = xTaskGetTickCount();
// Fix https://github.com/espressif/esp-idf/issues/4999
if (wait_time - ticks_start > ticks_to_wait) { // out of time
wait_time = I2C_CMD_ALIVE_INTERVAL_TICK;
wait_time = 1; // already spent too much time here, only wait a little more
} else {
wait_time = ticks_to_wait - (wait_time - ticks_start);
if (wait_time < I2C_CMD_ALIVE_INTERVAL_TICK) {
// if remaining time is more than 1s, just wait 1s and check the the status then
if (wait_time > I2C_CMD_ALIVE_INTERVAL_TICK) {
wait_time = I2C_CMD_ALIVE_INTERVAL_TICK;
}
}
Expand Down

0 comments on commit 6fcb9a5

Please sign in to comment.