Jump to content
43oh

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


Recommended Posts

Hello,

 

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
  while(ROM_I2CMasterBusBusy(MASTER_BASE));
 
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
Ethernet.begin(mac,ip);
udp.begin(localPort);
 
// Start I2C
Wire.setModule(0);
Wire.begin();
// Initilize the L3G4200D gyro
gyro.init();
}

 

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

 

void L3G4200D::getRawData()
{
while((i2cReadReg(L3G4200D_REGISTER_STATUS_REG) & 0x08) == 0);
 
Wire.beginTransmission(L3G4200D_ADDRESS);
Wire.write(L3G4200D_REGISTER_OUT_X_INC); // first register to start read from
Wire.endTransmission();
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;
  do{
 
    Wire.beginTransmission(113); 
    Wire.write(byte(0x00));     
    Wire.endTransmission();      
 
    Wire.requestFrom(113, 1);
    if(1 <= Wire.available())
      teste = Wire.read();
  }while(teste==255);
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.

Guest
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...