Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

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

$
0
0

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;
}

Viewing all articles
Browse latest Browse all 2077

Trending Articles