Wire library timing out

Hello

I use an OLED SSD1306 display with drivers I wrote using the Wire library. The interface used is the Twin Wire Interface, the Wire library uses the TWI.H/.C files.

I have noticed that if for some reason one of my wires get disconnected, say the SDA or the SCL, the Wire library hangs, and then aftger 4 seconds the watchdog comes in and resets the Arduino.

Ideally it would be better if there was a timeout on the Wire library so that it would not block forever, and maybe return an error when you try to write something, so then the code could take some action (other than a full reset which is the only option with the Watchdog).

Has anyone got any experience in this field to suggest anything? Many thanks

The I2C bus is not intended to be hot-pluggable, its designed for inter-IC commuications
on the same PCB (I2C = IIC = Inter-IC Communication). Since the Arduino has a hardware
block doing some of the protocol work it may be non-trivial to change the behaviour.

akis_t:
Ideally it would be better if there was a timeout on the Wire library so that it would not block forever, and maybe return an error when you try to write something, so then the code could take some action (other than a full reset which is the only option with the Watchdog).

When using the Arduino core "Wire" library, things are as they are: This library cannot detect faulty and hanging I2C hardware.

So if you'd need to detect such type of errors in your cabling or faulty I2C sensors you would need to use different code interacting with the I2C bus system.

In the AVR Atmega world, many users use the I2C (TWI) Master Software Library by Peter Fleury you can download here.

But be aware: Interacting with I2C slaves using the Peter Fleury library is much different from the interacting using the Arduino "Wire" library.