From d1025b6b5d98686abdf9d8c450f07da27e3b6012 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 9 Dec 2016 12:51:36 +0200 Subject: [PATCH] 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 https://github.com/espressif/arduino-esp32/issues/81 https://github.com/espressif/arduino-esp32/issues/53 https://github.com/espressif/arduino-esp32/issues/11 --- cores/esp32/esp32-hal-i2c.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-i2c.c b/cores/esp32/esp32-hal-i2c.c index ca7bc441..8fbb0b27 100644 --- a/cores/esp32/esp32-hal-i2c.c +++ b/cores/esp32/esp32-hal-i2c.c @@ -172,9 +172,13 @@ i2c_err_t i2cWrite(i2c_t * i2c, uint16_t address, bool addr_10bit, uint8_t * dat } } i = 0; + uint32_t fifotail = 0; while(idev->fifo_st.tx_fifo_end_addr; i++; i2c->dev->fifo_data.data = data[index++]; + // Wait for FIFO to update + while(i2c->dev->fifo_st.tx_fifo_end_addr == fifotail) {}; } i2cSetCmd(i2c, 1, I2C_CMD_WRITE, willSend, false, false, true); dataLen -= willSend; @@ -389,7 +393,7 @@ i2c_t * i2cInit(uint8_t i2c_num, uint16_t slave_addr, bool addr_10bit_en) i2c->dev->ctr.scl_force_out = 1 ; i2c->dev->ctr.clk_en = 1; - i2c->dev->timeout.tout = 2000; + i2c->dev->timeout.tout = 400000;//clocks max=1048575 i2c->dev->fifo_conf.nonfifo_en = 0; i2c->dev->slave_addr.val = 0;