Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMI160: How do you properly use "softreset"?


    Re: BMI160: How do you properly use "softreset"?

    Hello. I realise this is a fairly old post but I'm having exactly the same issue on BMX160 and wonder if you found a solution?
    I'm running 4-wire SPI at 8MHz (3.3V). Here is some code to show the issue:

    struct bmi160_dev sensor; = 0;
    sensor.interface = BMI160_SPI_INTF; = user_spi_read;
    sensor.write = user_spi_write;
    sensor.delay_ms = user_delay_ms;

    //STEP 1: read the chip-id to show we have a connection //
    uint8_t read_test=0;
    {bmi160_get_regs(BMI160_CHIP_ID_ADDR, &read_test, 1, &sensor); }
    // OUTCOME: gives read_test=0xD8 as expected //

    //STEP 2: write and read some data to a random register to show the write function is working //
    uint8_t data = 10;
    bmi160_set_regs(0x71, &data, 1, &sensor);
    bmi160_get_regs(0x71, &read_test, 1, &sensor);
    // OUTCOME: gives read_test=10 as expected //

    //STEP 3: soft-reset //
    data = 0xB6;
    bmi160_set_regs(BMI160_COMMAND_REG_ADDR, &data, 1, &sensor);
    delay_ms(200);        // I tried changing this value up to 3000
    bmi160_get_regs(BMI160_PMU_STATUS_ADDR, &read_test, 1, &sensor);
    // OUTCOME: gives read_test=0xFF from this point onwards all reads are 0xFF //

    //STEP 3: write and read some data exactly the same as before //
    data = 10;
    bmi160_set_regs(0x71, &data, 1, &sensor);
    bmi160_get_regs(0x71, &read_test, 1, &sensor);
    //OUTCOME: gives read_test=0xFF, not 10 as expected//

    //STEP 4: read the chip-id again//
    {bmi160_get_regs(BMI160_CHIP_ID_ADDR, &read_test, 1, &sensor); } // read_test=0xFF ...!!??
    //OUTCOME: now stuck in a loop. read_test=0xFF //

    For STEP 2 I also tried "bmi160_soft_reset(&sensor)" and "bmi160_init(&sensor)" (which also uses the soft-reset).
    These both had the same outcome.

    If anyone can see what I am missing it would be a great help.


    Re: BMI160: How do you properly use "softreset"?

    So I solved this not long after posting. In my 'user_spi_write(...)' the slave select pin was being pulled up straight after writing to the sensor. This worked fine except in the case of the soft-reset as this condition during power-up sends the sensor into I2C mode. An spi_read  or rising edge did not bring it back into SPI mode.
    The solution was to add a short delay (1ms) to the user_spi_write function before Slave-Select pull-up.


    Re: BMI160: How do you properly use "softreset"?

    The BMI160 protocol autodetection logic is as follows:
    1) After reset, part is in i2c mode.
    2) Upon rising edge of CSB pin, the part will switch to SPI mode until next reset.

    it is a good idea to included a dummy write to register 0x00 after each reset, to make sure the part is in SPI mode. In case you want to always use SPI, you can write the spi_en bit in Register 0x70 and back it up in the NVM, so that the part always start in SPI mode without dummy transaction. See datasheet section "Primary Interface I2C/SPI Protocol Selection"