Skip to content

Commit b7fbec7

Browse files
sylvioalvesfabiobaltieri
authored andcommitted
drivers: i2c: esp32: check busy line before transfer
I2C scan might fail as peripheral is still busy completing last operation. This makes sure transfer call waits for free line. Signed-off-by: Sylvio Alves <[email protected]>
1 parent 0badef8 commit b7fbec7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/i2c/i2c_esp32.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,20 @@ static int IRAM_ATTR i2c_esp32_transfer(const struct device *dev, struct i2c_msg
560560
{
561561
struct i2c_esp32_data *data = (struct i2c_esp32_data *const)(dev)->data;
562562
struct i2c_msg *current, *next;
563+
uint32_t timeout = I2C_TRANSFER_TIMEOUT_MSEC * USEC_PER_MSEC;
563564
int ret = 0;
564565

565566
if (!num_msgs) {
566567
return 0;
567568
}
568569

570+
while (i2c_hal_is_bus_busy(&data->hal)) {
571+
k_busy_wait(1);
572+
if (timeout-- == 0) {
573+
return -EBUSY;
574+
}
575+
}
576+
569577
/* Check for validity of all messages before transfer */
570578
current = msgs;
571579

0 commit comments

Comments
 (0)