I wrote a code to read 2 I2C sensors, the read transactions are done every minute.
Initially, the bus operate correctly, but after a random time, the sensors stop to respond.
As a debug, I wrote a message fail, which indicate that the action is called again.
If I gauge the SDA, and SDL signals, nothing appear when the transaction execute is called , and the message fail is display again.
I try to dispose the I2CDevice and create it again when the fails occurs, but it did not solve the issue.
I find out that if you short circuit the SDA and SDL signals with GND for a moment, the bus start to work again.
This is the read code:
public static byte[] Read(byte address, byte size, I2CDevice.Configuration configI2C)
{
byte[] regContent = new byte[size];
lock (dispositivoI2C)
{
transactionListRead[0] = I2CDevice.CreateWriteTransaction(new byte[1] { address });
transactionListRead[1] = I2CDevice.CreateReadTransaction(regContent);
dispositivoI2C.Config = configI2C;
if (dispositivoI2C.Execute(transactionListRead, 1000) == 0)
{
Debug.Print("Re-intentando transaccion I2C de lectura " + configI2C.Address.ToString() + " " + configI2C.ClockRateKhz.ToString());
dispositivoI2C.Dispose();
dispositivoI2C = null;
dispositivoI2C = new I2CDevice(configI2C);
if (dispositivoI2C.Execute(transactionListRead, 1000) == 0)
{
Debug.Print(“Falla al realizar las transaccion I2C de lectura”);
}
}
}
return (regContent);
}
Somebody can help me to get the I2C bus alive again.
you’re likely going to need to provide us with a simple complete repro code so that someone else can look at this. You’ll also need to tell us what I2C device you’re talking to.
Ordinarily you would not need to destroy the I2C config and I’m not surprised that the code you have written has not made a difference. The transaction failure should just be handled - and I would never ground SDA/SCL deliberately - it probably shows some other issue with your hardware or the way you’re trying to communicate with the I2C device (perhaps clock rate for example).
The devices I am communicating with are: BME280 and TSL2561.
I don’t think that the clock rate can be the reason of the failure, the devices support higher speeds.
As I wrote, the code work just fine for days, suddenly the signals dissapear, even if I disconnect the devices from the G80.
Can you help me with the appropiate way to handle the transaction failure?
I’ve seen the i2c bus quit entirely before, and not restart until the MCU is reset (both G30 and G400 have done it), but only when doing breadboarding and hot-plugging devices in. (Yes I live dangerously… lol)
Check your wiring over real close if it’s a breadboard. Make sure you don’t have anything loose, or inadvertently touching.
What ohm pullup are you using on SCL?
And you have a common ground plane between devices and microcontroller?