The main loop creates a gyro object then calls burst gyro. I declare the object as extern in main.h. And yes it is the only i2c device at the moment.
//declaration of I2c object in .h file
private:
I2C i2c_1;
//initializing gyro
ITG3200::ITG3200(PinName sda, PinName scl) : i2c_1(sda, scl) {
//400kHz, fast mode.
i2c_1.frequency(400000);
//Set FS_SEL to 0x03 for proper operation.
//See datasheet for details.
char tx[2];
tx[0] = DLPF_FS_REG;
//FS_SEL bits sit in bits 4 and 3 of DLPF_FS register.
tx[1] = 0x03 << 3;
i2c_1.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, tx, 2);
}
//function that runs at 100khz
void ITG3200::burstGyro(void){
i2c_1.frequency(400000);
char tx = GYRO_XOUT_H_REG;
char rx[6];
i2c_1.write((ITG3200_I2C_ADDRESS << 1) & 0xFE, &tx, 1,1);
i2c_1.read((ITG3200_I2C_ADDRESS << 1) | 0x01, rx, 6,1);
int16_t x_rate_raw = ((int) rx[0] << 8) | ((int) rx[1]);
int16_t z_rate_raw = ((int) rx[2] << 8) | ((int) rx[3]);
int16_t y_rate_raw = ((int) rx[4] << 8) | ((int) rx[5]);
gyro_data[0] = x_rate_raw/14.375 - x_rate_zero;
gyro_data[1] = z_rate_raw/14.375 - y_rate_zero;
gyro_data[2] = y_rate_raw/14.375 - z_rate_zero;
}
I'm running the itg3200 code, which has an I2C object as a class member. Upon initialization the i2c is set to 400kz, but when I write it outputs 100khz even if I set the frequency right before I call write. If I create a new I2c object right before the write function it works fine. The i2c object is private. Any ideas why it wont support 400khz?