Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMX160 SPI problems

    BMX160 SPI problems

    stephan_bosch
    New Poster

    Hi,

    I am currently struggling to get the BMX160 working on SPI. I am writing my own driver.

    1) The soft reset command seems to take a very long time (seconds). I can initially read the CHIPID register (0x00) correctly as 0xD8 but when I issue the soft reset command, it reads something else (most often 0x00) after a delay of at least 2ms. When I make my driver wait indefinitely for it to finally read 0xD8 after reset, it takes seconds until it succeeds (as indicated by breakpoint in CPU debugging). Initially and after the reset, I read 0x7f to get SPI initialized, as recommended. All of this I verified on the oscilloscope.

    2) When I omit the soft reset, I encounter problems at getting the sensors out of suspend mode. Writing the respective PMU commands has no effect and readback of the PMU status is stuck at zero. Increasing the respective post-write delays seems to have no effect.

     

    My colleague tried to get it working on an Arduino (with voltage level translator), using a BMI160 driver. There, it also fails to work on SPI, but seems to work fine on I2C.

     

    3 REPLIES 3

    Vincent
    Community Moderator
    Community Moderator

    According to the testing, the soft reset for BMX160 doesn't take so much time.

    Normally after issue soft reset command,  the sensor will enter reset sequence and it is response to register read / write within few ms. 

    Also the soft reset is not a mandatory steps for changing the PMU status in command register read / write.

    For further analyze your problem, can you post out your implementation code here first?

     

    The following is a relevant excerpt of the initialization code. The ellipses indicate where stuff is omitted.

    #define FORM_READ_REG( reg )             ( ( (reg) & 0x7F ) | 0x80 )
    #define FORM_WRITE_REG( reg )            ( ( (reg) & 0x7F ) | 0x00 )
    
    ...
    enum bmx160_reg
    {
        BMX160_REG_CHIPID                   = 0x00,
        ...
    	BMX160_REG_CMD                      = 0x7E,
    };
    
    enum bmx160_cmd {
    	...
        BMX160_CMD_SOFTRESET                = 0xB6,
    };
    
    ...
    static void BMX160_CMD( BMX160_OBJ* thisObj, enum bmx160_cmd cmd)
    {
        uint8_t reg;
    
        thisObj->spiIf->writeReg( thisObj->spiIf, &thisObj->spiSlave, FORM_WRITE_REG( BMX160_REG_CMD ), cmd );
    }
    
    ...
    {
        static uint8_t reg = 0x00;
        int try, i;
    	
        ...
    
        // Initialize sensor's SPI interface
        thisObj->spiIf->readReg( thisObj->spiIf, &thisObj->spiSlave, FORM_READ_REG( 0x7F ), &reg );
    
        // Read CHIP ID to make sure were talking to the expected BMX160 sensor
        // Usually works here in the first attempt
        reg = 0;
        try = 3;
        do {
            thisObj->spiIf->readReg( thisObj->spiIf, &thisObj->spiSlave,
                                     FORM_READ_REG( BMX160_REG_CHIPID ), &reg );
        } while (--try > 0 && reg != 0xd8 );
        if ( reg != 0xd8 ) {
            // Bad CHIP ID
            return -1;
        }
    
        // Reset the chip
        BMX160_CMD( thisObj, BMX160_CMD_SOFTRESET );
        // Wait for 2 ms (tested to be waiting sufficiently long using oscilloscope).
        delay_ms(2);
    
        // Initialize sensor's SPI interface again
        thisObj->spiIf->readReg( thisObj->spiIf, &thisObj->spiSlave,
                                 FORM_READ_REG( 0x7F ), &reg );
    
        // Test communication by reading CHIPID again.
        // Reads 0x00 or 0xFF and never succeeds within the 3 allotted attempts.
        reg = 0;
        try = 3;
        do {
            thisObj->spiIf->readReg( thisObj->spiIf, &thisObj->spiSlave,
                                     FORM_READ_REG( BMX160_REG_CHIPID ), &reg );
        } while (--try > 0 && reg != 0xd8);
        if ( reg != 0xd8 ) {
            // Bad CHIP ID
            return -1;
        }
        ...
    }
    ...

     

    Hi Stephan,

    Since you do not seem very far with your driver implementation, I would highly recommend that you simply write a generic SPI read/write and delay function, and use our free Sensor API.
    https://github.com/BoschSensortec/BMI160_driver
    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