This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Energia I2C library issue for f5529

Other Parts Discussed in Thread: ENERGIA


Hello,


I am trying to read from a 9 Degrees of Freedom board using I2C on the f5529. I wanted to start off by using Energia library functions to test but for some reason, my program gets stuck during  "Wire.endTransmission()". Any ideas on what is causing this? I have what code is written here so far, and I highlighted the line that's giving me trouble.

Thanks

#include <Wire.h>

#define ITG3200_ADDRESS (0xD0 >> 1)
//request burst of 6 bytes from this address
#define ITG3200_REGISTER_XMSB (0x1D)
#define ITG3200_REGISTER_DLPF_FS (0x16)
#define ITG3200_FULLSCALE (0x03 << 3)
#define ITG3200_42HZ (0x03)

int accelerometer_data[3];
int gyro_data[3];
int magnetometer_data[3];
int angle[3];

void i2c_write(int address, byte reg, byte data){
  
  // Send output register address
  Wire.beginTransmission(address);
  Wire.write(reg);
  Wire.write(data);
  Wire.endTransmission();
  digitalWrite(RED_LED, HIGH);
  
}

void i2c_read(int address, byte reg, int count, byte* data){
  
  int i = 0;
  
  //Send input register address
  Wire.beginTransmission(address);
  Wire.write(reg);
  Wire.endTransmission();
  //Connect to device and request bytes
  Wire.beginTransmission(address);
  Wire.requestFrom(address, count);
  while(Wire.available()){  //slave may send less than requested
    
    char c = Wire.read();  //receive a byte as character
    data[i] = c;
    i++;
  }
  
  Wire.endTransmission();
}

void init_itg3200(){
  
  byte data = 0;
  
  //Set DLPF to 42 Hz and set the scale to "Full Scale"
  i2c_write(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, ITG3200_FULLSCALE | ITG3200_42HZ);
  
  //Make sure the register value is correct.
  i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_DLPF_FS, 1, &data);
  
  Serial.print((byte)data);
}

void read_itg3200(){
  
  byte bytes[6];
  memset(bytes,0,6);
  
  //read 6 byres from the ITG3200
  i2c_read(ITG3200_ADDRESS, ITG3200_REGISTER_XMSB, 6, bytes);
  
  for (int i = 0; i < 3; i++){
    
    gyro_data[i] = (int)bytes[2*i + 1] + (((int)bytes[2*i]) << 8);
  }
}

void setup(){
 
 Wire.begin();
 
 pinMode(RED_LED, OUTPUT);
 
 Serial.begin(9600);
 Serial.print("begin\n");
 
 digitalWrite(RED_LED, LOW);
 
 for(int i = 0; i < 3; i++){
    
    accelerometer_data[i] = gyro_data[i] = magnetometer_data[i] = 0;
    angle[i] = 0;
  }
  
  init_itg3200();
}

void loop(){
  
  Serial.print(ITG3200_ADDRESS);
  Serial.print("\n");
  //delay(100); 
}

**Attention** This is a public forum