Bosch Sensortec Community

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

    [Question] BMI270 : BMI2_E_CONFIG_LOAD

    [Question] BMI270 : BMI2_E_CONFIG_LOAD

    Hugh
    New Poster

    Hi,

    I'm using STM32L4 MCU (STM32L476G-EVAL) and BMI270 shuttle board.

    Sometimes it works but mostly it fails to initialize. So I'm asking for your help.

    My setting is as follows:

    1. SPI 4-wire mode (STM32Cube_FW_L4_V1.16.0)

    SPI_HandleTypeDef hSPI1; /* Inertial Management */

    void MX_SPI_Init(void)
    {
    hSPI1.Instance = SPI1;
    hSPI1.Init.Mode = SPI_MODE_MASTER;
    hSPI1.Init.Direction = SPI_DIRECTION_2LINES;
    hSPI1.Init.DataSize = SPI_DATASIZE_8BIT;
    hSPI1.Init.CLKPolarity = SPI_POLARITY_LOW;
    hSPI1.Init.CLKPhase = SPI_PHASE_1EDGE;
    hSPI1.Init.NSS = SPI_NSS_SOFT;
    hSPI1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64; /* HSE 8MHz, Full-duplex, 750.0Kbps */
    hSPI1.Init.FirstBit = SPI_FIRSTBIT_MSB;
    hSPI1.Init.TIMode = SPI_TIMODE_DISABLE;
    hSPI1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
    hSPI1.Init.CRCPolynomial = 7;
    hSPI1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
    hSPI1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;

    HAL_SPI_Init(&hSPI1);
    }

    2. dummy_byte (https://github.com/BoschSensortec/BMI270-Sensor-API, v2.63.1)

    int8_t bmi270_init(struct bmi2_dev *dev)
    { if (dev->intf == BMI2_SPI_INTF) { dev->dummy_byte = 0;/*1*/ } }

    3. common.c

    #define BMI270_MAX_READ_WRITE_LEN 38

    static SPI_HandleTypeDef *hSPI = &hSPI1;
    static uint8_t spiBuf[BMI270_MAX_READ_WRITE_LEN+1];

    BMI2_INTF_RETURN_TYPE bmi2_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    uint8_t r;

    if (len == 0 || len > BMI270_MAX_READ_WRITE_LEN)
    return BMI2_E_OUT_OF_RANGE;

    if (reg_data == NULL)
    return BMI2_E_NULL_PTR;

    GpioOutputOff(SPI_CS_BMI270_GPIO_PORT, SPI_CS_BMI270_GPIO_PIN);
    spiBuf[0] = reg_addr;

    r = HAL_SPI_Transmit(hSPI, spiBuf, 1, 1000);
    //while(hSPI->State == HAL_SPI_STATE_BUSY); // wait for xmission complete
    if (r == 0)
    {
    memset(spiBuf, 0x00, sizeof(spiBuf));
    r = HAL_SPI_Receive(hSPI, spiBuf, len+1, 1000);
    //while(hSPI->State == HAL_SPI_STATE_BUSY); // wait for xmission complete
    memcpy(reg_data, &spiBuf[1], len); /* The first byte is dummy */
    }

    GpioOutputOn(SPI_CS_BMI270_GPIO_PORT, SPI_CS_BMI270_GPIO_PIN);

    return (r == 0) ? BMI2_INTF_RET_SUCCESS : BMI2_E_COM_FAIL;
    }

    BMI2_INTF_RETURN_TYPE bmi2_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
    {
    uint8_t r;

    if (len == 0 || len > BMI270_MAX_READ_WRITE_LEN)
    return BMI2_E_OUT_OF_RANGE;

    if (reg_data == NULL)
    return BMI2_E_NULL_PTR;

    GpioOutputOff(SPI_CS_BMI270_GPIO_PORT, SPI_CS_BMI270_GPIO_PIN);
    spiBuf[0] = reg_addr;
    memcpy(&spiBuf[1], reg_data, len);

    r = HAL_SPI_Transmit(hSPI, spiBuf, len+1, 1000);
    //while(hSPI->State == HAL_SPI_STATE_BUSY); // wait for xmission complete
    GpioOutputOn(SPI_CS_BMI270_GPIO_PORT, SPI_CS_BMI270_GPIO_PIN);
    return (r == 0) ? BMI2_INTF_RET_SUCCESS : BMI2_E_COM_FAIL;
    }

    void bmi2_delay_us(uint32_t period, void *intf_ptr)
    {
    uint32_t msec = period / 1000U;

    if (period % 1000U != 0U)
    msec++;

    vTaskDelay(msec); // I'm using FreeRTOS v202012.00-LTS
    }

    int8_t bmi2_interface_init(struct bmi2_dev *bmi, uint8_t intf)
    {
    memset(bmi, 0, sizeof(struct bmi2_dev));

    bmi->intf = intf;
    bmi->delay_us = bmi2_delay_us;
    bmi->read_write_len = BMI270_MAX_READ_WRITE_LEN;
    bmi->config_file_ptr = NULL; /* Assign to NULL to load the default config file */
    bmi->read = bmi2_spi_read;
    bmi->write = bmi2_spi_write;

    return BMI2_OK;
    }

    4. application

    res = bmi2_interface_init(&bmi2_dev, BMI2_SPI_INTF);

    uint8_t chipId;
    res = bmi2_get_regs(BMI2_CHIP_ID_ADDR, &chipId, 1, &bmi2_dev); // It does not work without this line
    res = bmi270_init(&bmi2_dev);

    5. spi packet

    I'm attaching an excel file. I did not check all 8K data but I think the 8K data is correct. The "load_status" is not valid.

     

    It worked only 3 times among hundreds trials.

    Would you help me please?

    Thanks,

    Hugh

    10 REPLIES 10

    Jet
    Occasional Contributor

    Hi Sir:

        Of cousre you can continue with that shuttle board, but first you should confirm your sensor chip with chip id because BMI260 and BMI270 are the same pin and package.

        And then correctly connect shuttle board pins to your platform.

        I use stm32F411 and shuttle board as well.

    Hi Jet,

    I added one more "BMI4XX_REG_READ" to read the chip id correctly. "0x24" was read for the second try.

    void StartBstTask(void const * argument)
    {
    ...
    BMI4XX_REG_READ(BMI2_I2C_PRIM_ADDR,0x00,1);
    BMI4XX_REG_READ(BMI2_I2C_PRIM_ADDR,0x00,1);
    BMI270_MODULE_INIT();
    }

    And I checked all the 8K data with my logic analyzer and there was no problem.

    But the result was "BMI2_E_CONFIG_LOAD" or "BMI2_E_DEV_NOT_FOUND" even with your reference code.

    Now I suspect my BMI260_A2 shuttle board and am going to prepare another shuttle board which may take several weeks.

    I will update the result then.

    Thanks for your support,

    Hugh

    Jet
    Occasional Contributor

    Hi Sir:

         Did you get data from register 0x21? what value?

         Did you observe the failure result during writing config file ? Like bmi2_set_adv_power_save()/set_config_load()/delay time/ SPI_CS voltage level after communcating.

        Recommend you to check these again.

        

    Hi Jet,

    I've got a Bosch Sensortec application board 2.0 from my dealer.

    I used Development Desktop 2.0, Bosch Sensortec application board 2.0, and my BMI260_A2 shuttle board and verified that my shuttle board works normally.

    I captured the SPI packets and found that the downloaded 8K config file is different with https://github.com/BoschSensortec/BMI270-Sensor-API.

    I applied the extracted config file from the SPI packets and it is initialized normally. I tried 1000 times and there were no error.

    I'm asking to my dealer why I should replace the config file and to release an official config file for me.

    Thanks,

    Hugh

    Jet
    Occasional Contributor

    Hi Sir:

         I talked to our internal guys, currenly because lack the related shuttle board, only based on what you said, we can't figure out the reason why the config file of API was failure. I re-checked our shuttle boards and get the correct result.

         If you need to look for the root cause, recommend you to contact the local FAE and offer your shuttle board to do further analysis.

     

     

    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