Bosch Sensortec Community

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

    BMI270 Config file load problem

    BMI270 Config file load problem

    Sara_r
    Member

    I'm using I2C bus to access BMI270 sensor with STM32H7 board. The chip ID of the sensor is read correctly from the register 0x00 with 0x24. I followed the steps of initialization, write_reg(0x7c,0x00), write_reg(0x59, 0x00), as the datasheet written. And these steps look alright since the functions return "HAL_OK" status.

    Then I used a for loop to burst write the config file that I found in BMI270 API into register 0x5E. I wrote 1 byte from the config file array everytime in the for loop. The writing status of the function I was using is "HAL_OK" as well, which seems alright. Then I wrote 0x01 into the register again like the datasheet said. However, when I read 0x5E (where I loaded the congif file) to check if the config file was burst written correctly, it looked completely different.

    Could you please help me with this problem? Any guidence would be appreciated!

    Here is my code

    HAL_StatusTypeDef return_value;
    uint8_t addr = 0x7c;
    uint8_t addr1 = 0x59;
    uint8_t addr2 = 0x5e;
    uint8_t addr2_sub = 0x5e;
    uint8_t addr_chk = 0x21;
    uint8_t val[1];
    val[0] = 0x00;
    uint8_t val_1[1];
    val_1[0] = 0x01;
    uint8_t return_addr_chk[1];
    // write_reg(0x7c, 0x00)
    return_value = HAL_I2C_Mem_Write(&hi2c1, (uint16_t)(BMI270_address), (uint16_t)addr, 1, val, 1, HAL_MAX_DELAY);

    if(return_value == HAL_OK){
        HAL_Delay(450);
        // write_reg(0x59, 0x00)   Burst write the config file
        return_value = HAL_I2C_Mem_Write(&hi2c1, (uint16_t)BMI270_address, (uint16_t)addr1, 1, val, 1, HAL_MAX_DELAY);
        if(return_value ==HAL_OK){
            for(uint16_t i=0; i<sizeof(bmi270_config_file); i++){
                return_value = HAL_I2C_Mem_Write(&hi2c1, (uint16_t)BMI270_address, (uint16_t)addr2_sub, 1, &bmi270_config_file[i], 1, HAL_MAX_DELAY);
                 if(return_value != HAL_OK){
                    break;
                 }
            }

        }
    }

    return_value = HAL_I2C_Mem_Write(&hi2c1, (uint16_t)(BMI270_address), (uint16_t)addr1, 1, val_1, 1, HAL_MAX_DELAY); // write_reg(0x59,0x01)
    if(return_value != HAL_OK){
    HAL_Delay(100);
    }
    return_value = HAL_I2C_Mem_Read(&hi2c1, (uint16_t)(BMI270_address|0x01), addr_chk, 1, return_addr_chk, 1, HAL_MAX_DELAY); // read INTERNAL_STATUS

    uint8_t config_file_check[8192];
    return_value = HAL_I2C_Mem_Read(&hi2c1, (uint16_t)(BMI270_address|0x01), 0x5e, sizeof(bmi270_config_file), config_file_check, sizeof(bmi270_config_file), HAL_MAX_DELAY); // check if the file loaded correctly

    7 REPLIES 7

    BSTRobin
    Community Moderator
    Community Moderator

    Hello Sara_r,

    There was BMI270 sensor API in github, you could also it.

    https://github.com/BoschSensortec/BMI270-Sensor-API

    Minhwan
    Community Moderator
    Community Moderator

    Hello, 

     

    I will elaborate more about config file load problem. 

    BMI270 API helps you to run BMI270 properly in right sequence. 

    https://github.com/BoschSensortec/BMI270-Sensor-API

    You need to put your spi function in bmi2_common.c

    And regarding bmi270 config file uploading and reading part, it is okay if you can upload 8kb config file at once. 

    However, if you need to upload it several times, you have to put right addresss in 0x5B (INIT_ADDR_0) as below. 

     

    config_size = sizeof(bmi2xx_config_file);
    file_count = 0;

    while (config_size > 0)
    {

    Wire.beginTransmission(BMI270_ADDR);
    Wire.write(INIT_ADDR_0);
    Wire.write(0x00);
    Wire.write(file_count);
    Wire.endTransmission();

    byte reg_data[32];
    /* dev_addr: I2C device address.
    reg_addr: Starting address for writing the data.
    reg_data: Data to be written.
    count: Number of bytes to write */
    // Begin I2C communication with provided I2C address
    Wire.beginTransmission(BMI270_ADDR);
    Wire.write(INIT_DATA);
    // Done writting, end the transmission
    Wire.endTransmission();


    // Requests the required number of bytes from the sensor
    Wire.requestFrom((int)BMI270_ADDR, (int)32);

    // Reads the requested number of bytes into the provided array

    uint16_t i = 0;

    for (i = 0; (i < 32 ) && Wire.available(); i++)
    {
    reg_data[i] = Wire.read(); // This is for the modern Wire library
    Serial.print(reg_data[i]);
    Serial.print(" ");
    }

    Serial.println("\t");


    filepos += 32;
    file_count += 1;
    config_size -= 32;
    delay(1);
    }

     

    Thank you. 

    Hi,

     

    Thanks for your reply!

    Now I'm using BMI270 API and trying to burst write the 8kb config file at once. So first I changed read_write_len to 8194 which is the size of the config file. Then I put the I2C function in user_i2c_reg_write and user_i2c_reg_write functions with my I2C function in bmi2_common.c. The i2c functions I'm using work well since it returns "HAL_OK". However, when I checked what was actually loaded in 0X5E, the loaded stuff is completely different from the config file. They are like {0x24, 0x21, 0x0, 0x10, 0x00, 0x00, ...}

    Here's how I changed the bmi2_common.c:

    /*!
    * @brief This function is for writing the sensor's registers through I2C bus.
    */
    int8_t user_i2c_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
        HAL_StatusTypeDef return_value;
        uint8_t *temp_data = reg_data;

        // Here I set the BMI270_address to be 0x68 << 1
        return_value = HAL_I2C_Mem_Write(&hi2c1, (uint16_t)BMI270_address, (uint16_t)reg_addr, length, temp_data, length, HAL_MAX_DELAY);
        if(return_value == HAL_OK){
             return 0;
        }
        /* Write to registers using I2C. Return 0 for a successful execution. */
    }

    /*!
    * @brief This function is for reading the sensor's registers through I2C bus.
    */
    int8_t user_i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
        HAL_StatusTypeDef return_value;
        return_value = HAL_I2C_Mem_Read(&hi2c1, (uint16_t)(BMI270_address | 0x01), (uint16_t)reg_addr, length, reg_data, length, HAL_MAX_DELAY);
        if(return_value == HAL_OK){
        /* Read from registers using I2C. Return 0 for a successful execution. */
            return 0;
        }
    }

    Minhwan
    Community Moderator
    Community Moderator

    Hello Sara, 

     

    Let's do step by step. 

    Here is my i2c config file upload function. For uploading config file, you have to consider about INIT_ADDR_0 as well unless you upload config file at once. 

    For burst write, you ensure that your system supports the length of bytes. Therefore, I don't recommened 8kB config file burst write at first time. 

    void upload_I2C_file(int config_size_, int file_count_, byte* filepos_)
    {
    Wire.beginTransmission(BMI270_ADDR);
    Wire.write(INIT_ADDR_0);
    Wire.write(0x00);
    Wire.write(file_count_);
    Wire.endTransmission();

    Wire.beginTransmission(BMI270_ADDR);
    Wire.write(INIT_DATA);
    Wire.write(filepos_,32);
    Wire.endTransmission();
    }

    //load config file and save as array
    config_size = sizeof(bmi2xx_config_file);
    //Serial.println(config_size);

    file_count = 0;

    byte* filepos = (byte *) bmi2xx_config_file;

    while (config_size > 0)
    {
    upload_I2C_file(config_size, file_count, filepos);

    filepos += 32;
    file_count += 1;
    config_size -= 32;
    delay(1);
    }

    If it works, you can increase 64 bytes. At that time file_count should be "file_count +=2;"

    Thanks, 

    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