I have googled and read a lot of posts and tried a lot of Wire.h and twi.c replacements but nothing seems to fix this one problem: Two Uno R3 talk to each other with out a problem via I2C. If one looses power / is disconnected then the remaining Uno hangs.
I am not a C programmer, just the basic Arduino language. Does anyone have a time out fix for just the Wire.endTransmission() function that freezes. I have tried lots of solutions I have found here and either they don't compile for Uno or don't work at all. Thank you in advance.
Kinda frustrated at this point... lots of reading (lot of technical stuff I don't understand yet) and no solution yet...
Check if the SDA and SCL lines are HIGH. If not, the I2C bus will block. I have a Mega and if you pull the SDA or SCL lines LOW, the I2C bus will block (freeze). On the Uno, the SDA is A4 and the SCL line is A5.
if((digitalRead(A4) == HIGH) && (digitalRead(A5) == HIGH))
{
// do your I2C stuff here
}
else
{
Serial.println("Failed - Lines LOW");
}
It probably won't do much good if the fail happens in the I2C Wire calls.
Pylon and SurferTim: Thanks for the feed back... how do I "pull up" the lines? I'm sorry but i am still new to this
I think all the "twi_writeTo()." are in the Wire.h file. My I ask you give me an example of what the code looks like for the timeout handling? Sorry but I don;t know "C" and most of this si still very new to me...
Thank you again for the help. There is no one I know around here that i can ask this stuff of... Thank you again for the help !!
The lines are pulled up by resistors. The Arduinos have weak pullup resistors that work at low speeds. They are activated with the Wire.begin call.
I tested the code I suggested above, and couldn't generate a lockup, but if the timing is perfect, it could still freeze. Maybe pylon will have something to use for a timeout.
Did you try the pull-ups? Put one (!) 4.7kΩ resistor between each SDA and 5V as well as SCL and 5V. This should fix it. Do it on that side that doesn't have the power outages, if both have outages put it to the slave.
Maybe pylon will have something to use for a timeout.
No, I don't have code for that, I never needed it. I just had a look at the code where one would have to insert it.
pylon: I will try it today when I get home from work. (I work a lot and it is hard sometimes to get back to the Arduino stuff). Thank you again for the advice.
It may be (I haven't tested this yet) the output transistors/fets create a ground condition on the I2C pins when the board is powered down, pulling the resistors to ground, or near enough to ground to overcome the pullup resistors.