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

    Hi,

     

    I tried using burst write to load the config file 32 bytes at once, but it failed. It looks like my MCU only supports the write/read length of 2 bytes and one byte. So I have two question:

    1. Is it okay if I use burst write to load the config file two bytes at once in the while loop? 

    2. Could you please expain the example code you replied in this post before? Here's the part that confuses me:

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

    Does this mean you wrote both "0x00" and "file_count_" into INIT_ADDR_0 every time when looping? 

    A supplyment of my last question:

    I tried writing two bytes into the register INIT_ADDR_0. (e.g I wrote 0xc8, 0x2e) However, the data I read from INIT_ADDR_0 is always 0x24 and 0x21. This is also resulted when I test other registers like INIT_CTRL other than INIT_ADDR_0.

    Also, if I wrote one byte into INIT_ADDR_0, only the last 6 bit of the data can be write/read. (I wrote 10001000 into INIT_ADDR_0. But I read 001000 from it after that.)

    Minhwan
    Community Moderator
    Community Moderator

    Hello Saa, 

     

    First, your system supports burst read operation. 

    If yes, could you follow below code? 

    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];
    // 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);
    }

    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