Hi,
i have some trouble with my I2C bus, because it freezes.
Sometimes 3 times a day; then another week running without problems i can't find where the problem is.
i've got 7 Arduino nano's with I2C extenders; for home automation
When the bus freezes; i've have to find the arduino which make the problem and press the reset button; then the bus releases and everything is working again.
i've added the following code to twi.c trying to release the bus and reset the connection
//TimeOUT
uint8_t twi_tout(uint8_t ini)
{
if (ini == 1) {
twi_toutc = millis() + 2000;
twi_timeoutenable = 1;
}
else if (ini == 2) {
twi_timeoutenable = 0;
}
if (twi_timeoutenable == 1) {
if (twi_toutc < millis()) {
twi_timeoutenable = 0;
twi_releaseBus();
//twi_stop();
twi_init();
return 1;
}
}
return 0;
}
before in and after every do-loop sequence i've added the following rules:
// wait for read operation to complete
twi_tout(1);
// while(TWI_MRX == twi_state){
if (twi_tout(0) == 1) return 0;
// continue;
// }
twi_tout(2);
; this works right; the arduino will function stand alone if the bus freezes
but i can't use the I2C network features.
is there any way to release the bus and reset the I2C connection for this slave or master?
( i thought that twi_releaseBus() and twi_init(); would solve the problem; but it isn't)
another thing i thought about; when i increase the speed of the bus; would it help or is the I2c then incompatible for other I2C devices?
Reinald