Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMI160 Programming

    BMI160 Programming

    Established Member


    I'd like to configure BMI160 with desired registers. To this aim, The associated functions are defined as follows:

    user_spi_write function


    int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t length)
            int8_t rslt = BMI160_OK; /* Return 0 for Success, non-zero for failure */
            reg_addr = reg_addr & 0x7F;
            SPI_BMI160_TX(reg_addr); // For write operations, the register should be ANDed with 0x7F.
                 /* Communicate len number of bytes: if TX - the procedure doesn't overwrite pData */
                 for (i = 0; i < length; i++)
                 return rslt;


    user_spi_read function:


    int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t length)
    int8_t rslt = BMI160_OK; /* Return 0 for Success, non-zero for failure */
    /* Communicate len number of bytes: if RX - the procedure sends 0x00 to push bytes from slave*/
    reg_addr = reg_addr | 0x80; // For read operation, the reg_addr should be ORed with 0x80.
    __delay_cycles(15); //after write operation, at least 2 micro-seconds is required for the next operation.
      for (i = 0; i < length; i++)
          SPI_BMI160_TX(0);            /* Possible to combining read and write as one access type */
          SPI_BMI160_RX(*reg_data++);     /* Store pData from last pData RX */
        return rslt;


    user_delay_ms function:


    int8_t user_delay_ms(uint32_t period)
    int8_t rslt = BMI160_OK; /* Return 0 for Success, non-zero for failure */
    return rslt;


    and also, I have defined a configure function that defines the registers:


    int Configuring(void)
        //  You may assign a chip select identifier to be handled later
          /**Initialize the BMI160***/
          struct bmi160_dev sensor;
 = 0;
          sensor.interface = BMI160_SPI_INTF;
 = user_spi_read;
          sensor.write = user_spi_write;
          sensor.delay_ms = user_delay_ms;
          int8_t rslt = BMI160_OK;
          /* After the above function call, accel_cfg and gyro_cfg parameters in the device
          structure are set with default values, found in the datasheet of the sensor */
          /*********Configuring the acc/gyro*************/
          // int8_t rslt = BMI160_OK;
          /* Select the Output data rate, range of accelerometer sensor */
          sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
          sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
          /* Select the Output data rate, range of Gyroscope sensor */
          sensor.gyro_cfg.odr = BMI160_GYRO_ODR_3200HZ;
          sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS;
          /* Select the power mode */
          sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
          sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
          /* Set the Power mode */
          rslt = bmi160_set_power_mode(&sensor);
          /* Set the sensor configuration */
          rslt = bmi160_set_sens_conf(&sensor);
           return rslt;


    The problem I have here is that at the start of executing the code in debug mode, it goes to exit.c (on code composer studio). Where do you think the problem comes from? Thanks and regards!

    Also for brevity, the spi functions are abbreviated as:


    //**The code is implemented on MSP432P401R**//
    #define SPI_BMI160_TX(X)   {while(!(UCB1IFG & UCTXIFG));UCB1TXBUF=X;}while(1==-1)
    #define SPI_BMI160_RX(X)   {while(!(UCB1IFG & UCRXIFG));X=UCB1RXBUF;}while(1==-1)
    #define SPI_BMI160_BEGIN   P6OUT &= ~BIT2;
    #define SPI_BMI160_END     P6OUT |= BIT2;



    1 REPLY 1

    Community Moderator
    Community Moderator


    I couldn't find out the error quicly.

    Maybe you can add printf() function and log more info, this can help you find the exception position.