Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMI160: How do you properly use "softreset"?

    bod609
    Member

    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;
    sensor.id = 0;
    sensor.interface = BMI160_SPI_INTF;
    sensor.read = 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;
    while(read_test!=216)
    {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);
    sensor.delay_ms(1);
    bmi160_get_regs(0x71, &read_test, 1, &sensor);
    sensor.delay_ms(1);
    //OUTCOME: gives read_test=0xFF, not 10 as expected//

    //STEP 4: read the chip-id again//
    while(read_test!=216)
    {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.

    bod609
    Member

    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.

    o_o
    Contributor

    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"

    o_o
    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