Skip to content

Commit f7df7fc

Browse files
author
blue-2357
committed
Update esp32-hal-i2c.c
wait for data to be latched and increase timeout in attempt to fix clock stretch issues Connected issues: http://esp32.com/viewtopic.php?f=19&t=632&p=2832#p2801 espressif/arduino-esp32#81 espressif/arduino-esp32#53 espressif/arduino-esp32#11
1 parent d59b4b2 commit f7df7fc

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: cores/esp32/esp32-hal-i2c.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat
172172
}
173173
}
174174
i = 0;
175+
uint32_t fifotail = 0;
175176
while(i<dataSend) {
177+
fifotail = i2c->dev->fifo_st.tx_fifo_end_addr;
176178
i++;
177179
i2c->dev->fifo_data.data = data[index++];
180+
// Wait for FIFO to update
181+
while(i2c->dev->fifo_st.tx_fifo_end_addr == fifotail) {};
178182
}
179183
i2cSetCmd(i2c, 1, I2C_CMD_WRITE, willSend, false, false, true);
180184
dataLen -= willSend;
@@ -389,7 +393,7 @@ i2c_t * i2cInit(uint8_t i2c_num, uint16_t slave_addr, bool addr_10bit_en)
389393
i2c->dev->ctr.scl_force_out = 1 ;
390394
i2c->dev->ctr.clk_en = 1;
391395

392-
i2c->dev->timeout.tout = 2000;
396+
i2c->dev->timeout.tout = 400000;//clocks max=1048575
393397
i2c->dev->fifo_conf.nonfifo_en = 0;
394398

395399
i2c->dev->slave_addr.val = 0;

0 commit comments

Comments
 (0)