I2C lockups: is it possible to adapt WSWire (alternative Wire library, has timeouts)?

Status
Not open for further replies.

XFer

Well-known member
Hello,
sometimes I have system lockups when I access external RTC modules, like described here:

http://www.paulodowd.com/2015/04/ds1307-woes-i2c-freezes-and-locks.html

The main problem is, that the standard Wire library does not have timeouts: so if an I2C access locks, a function like RTC.read() may wait forever!

The author suggests an alternate library (WSWire). But it's for Arduino AVR, while I'm using Teensy 3.2 (ARM).

Is it difficult to "port" an Arduino library?

Or, even better: maybe there's already a Teensy Wire library with timeout support?

Thank you very much!

Fernando
 
You want to use the i2c_t3 library, which is at: https://github.com/nox771/i2c_t3. From the documentation, you can set timeouts globally, as well as adding extra arguments to the write, read, and finish functions.

The user nox771 created the library, and this long running thread discusses it: https://forum.pjrc.com/threads/21680-New-I2C-library-for-Teensy3.

Note, in your main sketch, and all of the libraries you use, you will need to change the #include of Wire.h to i2c_t3.h.
 
In general I'd suggest trying to find the real problem. Using a timeout will help determining this.
The i2c_t3 library has return codes from the read/write functions that will help determine why it actually hangs.

For hard cases you'll need a logic analyzer or an oscilloscope or both.

Using the timeout permanently is a bandaid not good idea.

I am assuming that you've got proper external pullup resistors and checked voltages.
 
Thank you everyone!

Mmmm, can't find "Wire.freeBus()" anywhere :-( Not in the thread, nor in the documentation, neither in i2c_t3.h.

My bad! Here's what I was refering to..
Wire.resetBus(); - this is used to try and reset the bus in cases of a hung Slave device (typically a Slave which is stuck outputting a low on SDA due to a lost clock). It will generate up to 9 clocks pulses on SCL in an attempt to get the Slave to release the SDA line. Once SDA is released it will restore I2C functionality.
return: none
 
Status
Not open for further replies.
Back
Top