Hi, I am using the TM4C MCU with the TI BOOSTXL-SENSORS board for an assignment. This assignment requires me to communicate with the BMI160 over I2C. I can successfully read from registers, but it looks like I can't write to them. I have found the driver on git and the rslt from the initialisation is ok, the rslt from setting config is ok, but when I read 0x03 it's 0x0 but I expect it to be 0x14. Even when I attempt to write to these registers without the driver, It still doesn't change. The TI I2C api returns a successful transfer however, it doesn't seem to work. Can anyone tell me if there's an extra setting I need to be setting so I can access this? or any insight why this would be happening? I am also using the OPT3001 on the same I2C and can write and read from that no problem. Wrapper init - user read and write - I2C read and write void sensorBmi160Init(I2C_Handle *i2c){ i2c_bmihandle = i2c; System_printf("Init Bmi struct\n"); System_flush(); bmi160_sensor.id = BMI160_I2C_ADDR; bmi160_sensor.interface = BMI160_I2C_INTF; bmi160_sensor.read = sensorBmi160Read; bmi160_sensor.write = sensorBmi160Write; bmi160_sensor.delay_ms = user_delay; int8_t rslt = BMI160_OK; System_printf("Call Bmi api init\n"); System_flush(); rslt = bmi160_init(&bmi160_sensor); if(rslt == BMI160_OK){ System_printf("BMI160 Init ok.\n"); }else{ System_printf("BMI160 Init failed.\n"); return; } /* Configure the accelerometer */ bmi160_sensor.accel_cfg.odr = BMI160_ACCEL_ODR_100HZ; bmi160_sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G; bmi160_sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4; bmi160_sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE; /* Configure the gyroscope */ bmi160_sensor.gyro_cfg.odr = BMI160_GYRO_ODR_100HZ; bmi160_sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS; bmi160_sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE; bmi160_sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE; rslt = bmi160_set_sens_conf(&bmi160_sensor); /* Check rslt for any error codes */ } int8_t sensorBmi160Write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len){ if(writeI2C(i2c_bmihandle, dev_addr, reg_addr, data, len)){ return BMI160_OK; } return BMI160_E_COM_FAIL; } int8_t sensorBmi160Read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len){ System_printf("read: in\n"); System_flush(); if(readI2C(i2c_bmihandle, dev_addr, reg_addr, data, len)){ return BMI160_OK; } return BMI160_E_COM_FAIL; } bool writeI2C(I2C_Handle *i2c, uint8_t SLAVE, uint8_t REG, uint8_t *DATA, uint16_t len) { I2C_Transaction i2cTransaction; uint8_t txBuffer[5]; txBuffer[0] = REG; //This the register you want to read int i; for(i = 0; i<len; i++){ txBuffer[i+1] = DATA[i]; } i2cTransaction.writeBuf = NULL; i2cTransaction.readCount = 0; i2cTransaction.slaveAddress = SLAVE; i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = len; bool suc = I2C_transfer(*i2c, &i2cTransaction); System_printf("transfer write %i\n", suc); System_flush(); return suc; } bool readI2C(I2C_Handle *i2c, uint8_t SLAVE, uint8_t REG, uint8_t* data, uint16_t len) { I2C_Transaction i2cTransaction; uint8_t txBuffer[1]; txBuffer[0] = REG; //This the register you want to read i2cTransaction.slaveAddress = SLAVE; i2cTransaction.writeBuf = txBuffer; i2cTransaction.writeCount = 1; i2cTransaction.readBuf = data; i2cTransaction.readCount = len + 1; bool suc = I2C_transfer(*i2c, &i2cTransaction); System_printf("transfer read %i\n", suc); System_flush(); return suc; }
... View more