Hi,
I used Due to connect to g-sensor BMA250E via SDA/SCL and external interrupt, pin 7. At beginning, I found my program ran well for a while but suddenly stopped. With the help of logic analyzer, I realized the I2C protocol was frozen because the SDA was kept low. So I tried to minimized my code to setup() and loop().
In the code below, you can see the BMA250E was set as new data interrupt mode. It means the BMA250 would emit a toggled signal from its INT pin whenever the data is updated. However, I didn't attach this interrupt signal to an ISR in my code, but still kept it connected to the Due, pin 7 with a wire.
in the loop() function, I simply wrote a fixed value to a register and read back six registers .
#include <Wire.h>
void setup()
{
// enable TWI library, and set SCL as 400kHz
Wire.begin();
Wire.setClock(400000L);
//
// initialize BMA250E
//
//enable new data ready interrupt
Wire.beginTransmission(0x18);
Wire.write(0x17);
Wire.write(0x10);
Wire.endTransmission(true);
//new data interrupt outupt to INT1
Wire.beginTransmission(0x18);
Wire.write(0x1A);
Wire.write(0x01);
Wire.endTransmission(true);
//INT1 active high, push-pull
Wire.beginTransmission(0x18);
Wire.write(0x20);
Wire.write(0x01);
Wire.endTransmission(true);
}
void loop()
{
// write a fixed value to register 0x17
Wire.beginTransmission(0x18);
Wire.write(0x17);
Wire.write(0x10);
Wire.endTransmission(true);
//read six registers from 0x02
Wire.beginTransmission(0x18);
Wire.write(0x02);
Wire.endTransmission(true);
Wire.requestFrom(0x18, 6);
}
The figure below was from my logic analyzer. Obviously, the I2C protocol is interrupted and not properly finished. The TWI library seems not have a "time-out" or "watchdog" mechanism to release the I2C bus. To clarify the situation, disabling the new data interrupt of BMA250E was also tried. It ran smoothly without any problem.
My question is how a toggled signal on the digital pin can conflict the I2C protocol and freeze it? It looks like a hardware issue but not a firmware issue. Does someone else have the same problem? I have tried to solve this already three months. I would very appreciate that someone can help me to figure out this weird situation. Thank you a lot.
