I2C timeout?

Hi!

I'm using an I2C network to connect a couple of Arduclemas (an Arduino derivative with screw terminals on all pins, and I2C pullUp resistors).

My problem is this: if one node card (microcontroller) fails or leaves the network, the Master seems to block indefinitely while doing Wire.endTransmission(). I can't seem to find a way to check if the node is alive before talking to it, or recover gracefully (and quickly) when the communication fails. The ideia is to have a timeout when communicating; if it takes more than a few ms just return in error and keep going.

Has anyone found a way to deal with this?
Thanks!

Óscar

It's a 'feature' of the I2C library or rather what it is built on.
It is this section that is hanging:-

uint8_t TwoWire::endTransmission(void)
{
  // transmit buffer (blocking)
  int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1);

The slave device isn't acknowledging what is sent to it by pulling the pin low. The I2C bus was never meant to be used in this way of being able to plug and unplug devices.
Of course what you need to do is to make that write call a non blocking call by having a time out in it. Unfortunately a quick look does not reveal where it is.
Maybe some softie can help.

that was always a thorn in my side as well... yet i never really made something about it because i always thought someone else would do it who has more knowleadge about avr programming.

Seeing it as it is - wouldnt it be possible to do something like:
(Pseudocode)

uint8_t TwoWire::endTransmission(void)
{
  start_interrupt check();
  int8_t ret = twi_writeTo(txAddress, txBuffer, txBufferLength, 1);
...
}

interrupt check()
{
timeout = 1000;
waited++
if (waited> timeout)
{
    'end' end_transmission
}
}