Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 initialization issue with nRF52832

    BMI270 initialization issue with nRF52832

    niag
    Occasional Visitor

    Hi,

    as many other people in this forum, I am facing problems when trying to initialize the BMI270 IC. In my case it is connected to an nRF52832 over I2C at 100kHz. I am using the c code found on github and all I had to do was to implement the read & write functions.

    In the beginning, while running the bmi2_soft_reset() function included in the bmi270_init() function (actually in the bmi2_sec_init()), I got back error -9: BMI2_E_CONFIG_LOAD. Digging a bit deeper I then discovered that after loading the config file, upon reading the internal status register an internal status error of type "0x02 - init_err" is returned from the INTERNAL_STATUS register.

    I then decided to read back the config file, after loading it and voila... I found out that, quite weirdly I must say, bytes 2 and 3 of every burst write appears to be overwritten with 0x00 instead of the bytes contained in the config file.

    For example, if I write this with write burst length = 4 (I substituted the real config file bytes with test bytes for the purpose of clarity)

    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10

    I get back 

    0x01, 0x00, 0x00, 0x04, 0x05, 0x00, 0x00, 0x08, 0x09, 0x00, 0x00, 0x0c, 0x0d, 0x00, 0x00, 0x10

    That happens regardless of the write burst length (I saw the same with with 4 and 8 burst length). My burst read length was bigger than the burst write length, so I think we can exclude read errors.

    Any idea why this is happening? Can it be something wrong on the BMI270 side?

    I also plan to observe the I2C signals with an oscilloscope to actually see what is happening.

    In case it helps, this is my i2c_write function:

    int8_t user_i2c_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
        ret_code_t err_code = NRFX_SUCCESS;
    
        /** Combine reg_addr and reg_data to a single tx_buffer */
        uint8_t *buf = malloc((1 + length) * sizeof(uint8_t));
    
        if (buf == NULL) {
            return 1;
        }
    
        buf[0] = reg_addr;
        memcpy(&buf[1], reg_data, length * sizeof(uint8_t));
        
        /* Make sure the bus is not active */
        while(nrfx_twim_is_busy(intf_ptr));
        
        /* Set-up and do the I2C transaction */
        nrfx_twim_xfer_desc_t const twim_xfer_desc =
        {
            .type             = NRFX_TWIM_XFER_TX,
            .address          = dev_addr,
            .primary_length   = length + 1,
            .p_primary_buf    = buf,
        };
        err_code = nrfx_twim_xfer(intf_ptr, &twim_xfer_desc, 0);
    
        free(buf);
    
        /* Wait until transaction is over */
        while(nrfx_twim_is_busy(intf_ptr));
    
        /* Write to registers using I2C. Return 0 for a successful execution. */
        if (err_code == NRFX_SUCCESS) {
            return 0;
        }
        else {
            return 1;
        }
    }

    and this is my i2c_read function:

    int8_t user_i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
        ret_code_t err_code = NRFX_SUCCESS;
    
        /* Make sure the bus is not active */
        while(nrfx_twim_is_busy(intf_ptr));
        
        /* Set-up and do the I2C transaction */
        nrfx_twim_xfer_desc_t const twim_xfer_desc =
        {
            .type             = NRFX_TWIM_XFER_TXRX,
            .address          = dev_addr,
            .primary_length   = 1,
            .p_primary_buf    = &reg_addr,
            .secondary_length = length,
            .p_secondary_buf  = reg_data,
        };
        err_code = nrfx_twim_xfer(intf_ptr, &twim_xfer_desc, 0);
    
        /* Wait until transaction is over */
        while(nrfx_twim_is_busy(intf_ptr));
    
        /* Write to registers using I2C. Return 0 for a successful execution. */
        if (err_code == NRFX_SUCCESS) {
            return 0;
        }
        else {
            return 1;
        }
    }

     

    1 REPLY 1

    Jet
    Occasional Contributor

     Did you set read/write length( uint16_t read_write_len)? Is there the limitation of read/wirte length on your platform?

    Did you get CHIP_ID of BMI270(read register BMI2_CHIP_ID_ADDR )?

    Could you print the reg_data and length in your read/write function to cofirm the related translated values?

    if you need,  the relative reference code based on STM32F4 platform will be offered.

    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