Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 accel data anomily, out by factor of 4

    BMI270 accel data anomily, out by factor of 4

    jichen
    New Poster

    Hello all,

    I modified the bmi270 api accel examples to make it work in STM32F205 and successfully read the accel data,

    but with problems that:

    1) The accelerometer data is out by factor of 4

    x=0.02 m/ss

    y=2.37 m/ss (anticipate it close to 1G, 9.8m/ss)

    z=-0.4 m/ss

    2) Changing the range made no difference to the data (double checked Register (0x41) ACC_RANGE and sure the change was wrote the register correctly)

    During my self debug,  I narrow down the problem is  getting BMI2_E_ACC_INVALID_CFG error in set_accel_config()

    But I got all BMI2_OK in other settings and BMI2_E_ACC_INVALID_CFG  error doest not tell me more details except my ACCEL configuration should have problem.

     

    My code is mostly the accel example from BMI270-Sensor-API

    https://github.com/boschsensortec/BMI270-Sensor-API/tree/master/bmi270_examples/accel

    with following changes to make it work with stm32

    1) redefine bmi2_interface_init() with

    struct bmi2_dev bmi270_dev;
    bmi270_dev.read = bm_spi_read;
    bmi270_dev.write = bm_spi_write;
    bmi270_dev.delay_us = delayUs;
    bmi270_dev.read_write_len = SPI_BUFF_SZ-1; (#define SPI_BUFF_SZ (1024+1))
    bmi270_dev.intf = BMI2_SPI_INTF;//configure BMI270 SPI
    bmi270_dev.intf_ptr = &hspi2;
    bmi270_dev.config_file_ptr = NULL;
    2)define bm_spi_read with stm32spi
    static int8_t bm_spi_read(uint8_t reg_addr, uint8_t* data, uint16_t len, uint8_t dev_addr)
    {
    UNUSED(dev_addr);
    if( len > SPI_BUFF_SZ ) {
    Error_Handler();
    }
    uint8_t txarr[1] = { reg_addr };//not sure if the size always 1 but highly possible
    uint8_t rxarr[SPI_BUFF_SZ] = {};
    HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_RESET);
    HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr,1,COMM_DELAY);
    HAL_SPI_Receive(&hspi2,rxarr,len,COMM_DELAY);
    HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_SET);
    memcpy(data, rxarr, len);
    return (status == HAL_OK ? BMI2_OK : BMI2_E_COM_FAIL);
    }
    3)define bm_spi_write with stm32spi
    int8_t bm_spi_write(uint8_t reg_addr, uint8_t* data, uint16_t len, uint8_t dev_addr)
    {
    UNUSED(dev_addr);
    if( len > SPI_BUFF_SZ - 1) {
    Error_Handler();
    }
    uint8_t txarr[SPI_BUFF_SZ] = { reg_addr };
    memcpy(txarr + 1, data, len);
    HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_RESET);
    HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr, len + 1,COMM_DELAY);
    HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_SET);
    return (status == HAL_OK ? BMI2_OK : BMI2_E_COM_FAIL);
    }
     
    My problem should be exact with the post in below link

    https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI270-accel-data-anomily/td-p/15622

    Unfortunately, this post does not give out the details how the problem was finally solved

     

     

     

    6 REPLIES 6

    Hi Minhwan,

    Thanks for responsing!

    Yes! I am using the Bosch offical API from github

    I think I mistakely typed the output of register 0x40 and 0x41

    My 0x40 read is 0xA9

    and 0x41 read is 0x00

    So, value from these 2 registers should looks OK?

    I found more clues about my issue, it seems more related with the config.cfg.acc.odr setting

    when I set the config.cfg.acc.odr less than 

    config.cfg.acc.odr = BMI2_ACC_ODR_6_25HZ;

    The output is wrong and out by factor of 4.

    But when I set config.cfg.acc.odr bigger than 

    config.cfg.acc.odr = BMI2_ACC_ODR_6_25HZ;

    The output is correct

    Do you have ideal what can cause this ?

     

    Thanks!

     

    Minhwan
    Community Moderator
    Community Moderator

    Hi Jichen, 

     

    Sorry for late response. 

    Your setting is not correct. 

    Normal mode (Performance mode is available) range is 12.5 Hz to 1600Hz. 

    And, 6.25 Hz or lower Hz should be set to low power mode. 

    You have to put "config.cfg.acc.filter_perf = BMI2_POWER_OPT_MODE;"

    You can check the ODR in data sheet. 4.6.4 Accelerometer Data Processing in Normal and Performance Mode and 4.6.5 Accelerometer Data Processing in Low Power Mode. 

    Please accept solution if my answer is enough for your questions 🙂 

    Thank you. 

    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