Jump to content

I2C hangs at Wire.endtransmission() after running for a while

Recommended Posts



I just received a TM4C1294XL connected launchpad. I'm trying to get it working with L3G4200D gyroscope (it's a module from Parallax with pull-ups). The program runs as expected for a while and then freezes and I have to long press the reset button to get it working again. By importing the Energia sketch into CCSv6, I was able to find the program hangs at the Wire.endtrsmission(), in particular at line


  //Wait for any previous transaction to complete
in the Wire library. I tried with another sensor and experience the same problem. Could somebody help me out?
The related code is attached below (sorry for not knowing how to format the code in the post):
void setup()
// Start the Ethernet and UDP
// Start I2C
// Initilize the L3G4200D gyro


void loop()
currentTime = millis();
interval = currentTime - lastTime;
if (currentTime - lastTime >= 100)
// Serial.println(interval);
lastTime = currentTime;
// Get sensor data
IPAddress remoteIP(192,168,1,10);
uint16_t remoteLocalPort = 13000;
udp.beginPacket(remoteIP, remoteLocalPort);
udp.write(txPacketBuffer, TX_PACKET_SIZE);


void L3G4200D::getRawData()
while((i2cReadReg(L3G4200D_REGISTER_STATUS_REG) & 0x08) == 0);
Wire.write(L3G4200D_REGISTER_OUT_X_INC); // first register to start read from
Wire.requestFrom(L3G4200D_ADDRESS, 6);
while(Wire.available() < 6);
byte raw_low;
byte raw_high;
raw_low = Wire.read();
raw_high = Wire.read();
data.xRawDPS = (raw_high << 8) | raw_low;
raw_low = Wire.read();
raw_high = Wire.read();
data.yRawDPS = (raw_high << 8) | raw_low;
raw_low = Wire.read();
raw_high = Wire.read();
data.zRawDPS = (raw_high << 8) | raw_low;
Link to post
Share on other sites

you could add a timeout in the while with milis();


i can't realy advise in the specific sensor but other thing i did was specific for srf08 :

before i did a resquest i made sure the sensor was not busy. i kept requesting the software revision and when it answered then it would be not busy, like so:


  int teste=255;
    Wire.requestFrom(113, 1);
    if(1 <= Wire.available())
      teste = Wire.read();
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...