Bosch Sensortec Community

    Can't change BMI160 PMU states.

    Highlighted
    New Poster

    Can't change BMI160 PMU states.

    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

    Spoiler

    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 */

    }


    Spoiler

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

    Spoiler

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

     

     

    Tags (1)
    1 REPLY 1
    Highlighted
    Community Moderator

    Re: Can't change BMI160 PMU states.

    Hi,

    Thanks for your inquiry.

    After power on BMI160 both accelerometer and gyroscope will be in suspend mode by default. That is why you get value of 0x00 back from status register 0x03. Please do the following to bring accel and gyro to normal mode.

    Write value of 0x11 to command register 0x7E; // bring accel to normal mode

    Delay 5ms; // wait for the accel to stablize

    Write value of 0x15 to command register 0x7E; // bring gyo to normal mode

    Delay 80ms; // wait for the gyro to stablize

    Read register 0x03; // now you should get the valus of 0x14 back

    Thanks.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist