Closed zelll closed 7 years ago
I can think of 2 scenarios where this change would help:
Can you please check which one applies to your hardware setup? I.e. does the NEO-M8N use clock stretching and which resistance have your pull-ups?
https://www.u-blox.com/sites/default/files/NEO-M8-FW3_DataSheet_%28UBX-15031086%29.pdf 4.5 DDC timing diagrams The DDC interface is I2C Fast Mode compliant. For timing parameters consult the I2C standard. The maximum bit rate is 400 kb/s. The interface stretches the clock when slowed down when serving interrupts, so real bit rates may be slightly lower.
Yes, it stretches the clock.
I use 2.2K to pull-up (even tried 1K).
I tried to slow down i2c with #define i2c_master_wait(us) os_delay_us(5*us)
, (maybe) improved, but not resolve completely.
Your code change looks as though it would solve the clock stretching problem. I'm slightly nervous that it can loop infinitely. However, all that i2c code seems to ignore problems, so maybe it is OK. The watchdog will kill it anyway and restart the platform if something goes wrong.
Please submit a PR with your change.
PR now merged.
Expected behavior
Read/Write correctly
Actual behavior
SCL signal does not go up immediately sometime (maybe M8N does not release SCL).
I tried add a while loop to check SCL after set SCL to high in i2c_master_setDC(). It resolves the problem.
Test code
Code below prints wrong result from time to time
NodeMCU version
1.5.4.1-master_20161001
Hardware
NodeMCU U-blox NEO-M8N GPS module