Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMP280 read reset values in normal mode

    BMP280 read reset values in normal mode

    New Poster


    Reading temp and press from BMP280 in normal mode, return reset values 0x80000 for both of them.

    In forced mode reading returns expected values.

    I use the APIs provided here, ported for ESP32.

    I'm aware about the old topic but the behavior i see is different. and the sensor power supply should be fine.

    In my case after a power cycle of the system, the reading is normal. If i reset esp32 (hard or soft) then reading returns 0x80000. This happens only if power mode is set to BMP2_POWERMODE_NORMAL. If power mode is set to BMP2_POWERMODE_FORCED then no issue.

    API sequence used is the following in both cases: normal and forced

    1. bmp2_init()
    2. bmp2_get_config() // get initial configuration
    3. bmp2_set_power_mode() // set power mode and new configuration
    4. bmp2_get_config() // ensure new values are stored on device
    5. // bmp2_set_regs() //select forced mode in 0xf4 ; commented out in normal mode
    6. bmp2_get_status() // not needed for normal mode, but i keep it here for forced mode
    7. bmp2_get_sensor_data()
    8. loop to #5

    The configuration i use is this one:

    conf.filter = BMP2_FILTER_COEFF_16;
    conf.os_pres = 0; 
    conf.os_temp = 0; 
    conf.odr = BMP2_ODR_500_MS;

    and i can see it in registers.

    It puzzles me it works fine after power cycle but not after reset. My guess is that a power cycle does a reset of bmp280 different from the software reset.

    What can i do to bring the sesor in working mode after reset?






    9 REPLIES 9

    Community Moderator
    Community Moderator


    Thanks for your inquiry.

    Please refer to the sample code at for more information.

    BMP280 oversampling on pressure and temperature means that BMP280 will take number of measurements internally and then average them as the final measurement and then update the data registers with the final measurement. conf.os_pres = 0 or conf.os_temp = 0 means that pressure sensor or temperature sensor will be bypassed or skipped. You will always get 0x80000 from pressure and temperature data registers.  conf.os_mode = BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION means that conf.os_pres = x16 and conf.os_temp = x2. Therefore, BMP280 pressure sensor will take 16 measurements internally and then average them as the final measurement and then update pressure data registers with the final measurement.

    So in your code, you cannot set conf.os_pres = 0 and conf.os_temp = 0 after soft reset or power on reset (hard reset), because both pressure sensor and temperature sensor will be skipped. You also need to call function "rslt = bmp2_set_config(&conf, &dev);" after you configure BMP280 oversampling. Then the issue should be resolved.


    Thanks for the reply.

    The way you implemented API, or at least the version available on github shows both functions bmp2_set_config(), which you recommend  and bmp2_set_power_mode(), which i use, are calling internally static function conf_sensor(mode, conf, dev).

    The difference is that bmp2_set_config() calls conf_sensor() with mode set to BMP2_POWERMODE_SLEEP, while bmp2_set_power_mode() calls conf_sensor() with mode provided by the caller . So bmp2_set_power_mode() will set both: power mode and sensor configuration and the power mode value is the one choosed by me at the call time. This is the reason i call only bmp2_set_power_mode().

    Further on, in conf_sensor(),  you call set_os_mode() which fills 0xf4 register with the bit values for osrs_t and osrs_p. These values are calculated only based on the value provided in conf->os_mode and disregards values provided in conf->os_temp and conf->os_pres. So whatever values might be in conf->os_temp and conf->os_pres are meaningless.

    I can confirm with my sequece of code the values in oxf4 and 0xf5 are the one expected. bmp2_get_config() returns these values

    conf.filter = 4

    conf.os_temp = 5

    conf.os_pres = 2

    conf.odr = 4

    I tryed also your recommendations but the result is the same.

    Community Moderator
    Community Moderator

    Hi Ves011, 


    Could you share your code? 

    I will look into it. 


    Here is the part of the code which reproduce the issue. It does not include the ESP32 specific part, but if you think is relevant i can share it also.

    static int get_bmp_data(bmp_data_t *bmpdata)
        int res = BMP2_E_COM_FAIL;
        uint8_t reg_addr = 0xf4, reg_data;
        struct bmp2_status bmps;
        if(bmpdev.power_mode == BMP2_POWERMODE_FORCED)
            reg_data = 0;
            reg_data = osrs_t << 5 | osrs_p << 2 | 1;
            res = bmp2_set_regs(&reg_addr, &reg_data, 1, &bmpdev);
            res = BMP2_OK;
        if(res == BMP2_OK)
            if(bmpdev.power_mode == BMP2_POWERMODE_FORCED)
                while((res = bmp2_get_status(&bmps, &bmpdev) == BMP2_OK) && bmps.measuring == 1)
                    //ESP_LOGI(TAG, "bmp280 busy");
            res = bmp2_get_sensor_data(bmpdata, &bmpdev);
            if(res == BMP2_OK)
                char buf[50];
                ESP_LOGI(TAG, "Temperature = %8.3f", bmpdata->temperature);
                ESP_LOGI(TAG, "Pressure    = %8.3f", bmpdata->pressure);
                //sprintf(buf, "%.3f\1%.3f", bmpdata->temperature, bmpdata->pressure);
                //publish_state(buf, 0, 0);
        return res;
        uint8_t pmode = 0xff;
        struct bmp2_config conf;
        bmpdev.intf = BMP2_I2C_INTF;
        bmpdev.delay_us = my_usleep; = bmp280_read;
        bmpdev.write = bmp280_write;
        bmpdev.intf_ptr = NULL;
        int res = i2c_master_init();
        res = bmp2_init(&bmpdev);
        if(res == BMP2_OK)
            res = bmp2_get_config(&conf, &bmpdev);
            if(res == BMP2_OK)
                ESP_LOGI(TAG, "bmp280 chip ID: %0x %0x %0x %0x %0x %0x %0x", bmpdev.chip_id, conf.filter, conf.odr, conf.os_mode, conf.os_pres, conf.os_temp, conf.spi3w_en);
                ESP_LOGI(TAG, "bmp280 cal param: %6d %6d \n%6d %6d %6d %6d %6d\n%6d %6d %6d %6d %6d", bmpdev.calib_param.dig_t1, bmpdev.calib_param.dig_t2
                                        , bmpdev.calib_param.dig_p1, bmpdev.calib_param.dig_p2, bmpdev.calib_param.dig_p3, bmpdev.calib_param.dig_p4, bmpdev.calib_param.dig_p5
                                        , bmpdev.calib_param.dig_p6, bmpdev.calib_param.dig_p7, bmpdev.calib_param.dig_p8, bmpdev.calib_param.dig_p9, bmpdev.calib_param.dig_p10);
                conf.os_mode = BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
                conf.filter = BMP2_FILTER_COEFF_16;
                conf.os_pres = 0; // BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
                conf.os_temp = 0; //BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
                conf.odr = BMP2_ODR_500_MS;
                res = bmp2_set_power_mode(BMP2_POWERMODE_NORMAL, &conf, &bmpdev);
                if(res == BMP2_OK)
                    res = bmp2_get_config(&conf, &bmpdev);
                    ESP_LOGI(TAG, "bmp280 config: %0x %0x  %0x %0x  %0x\n", conf.filter, conf.odr, conf.os_pres, conf.os_temp, conf.spi3w_en);
                    osrs_t = conf.os_temp;
                    osrs_p = conf.os_pres;
                    res = bmp2_get_power_mode(&pmode, &bmpdev);
                    ESP_LOGI(TAG, "bmp280 power mode: %0x", pmode);
                    ESP_LOGI(TAG, "error during configuration %d", res);
        if(res != BMP2_OK)
            ESP_LOGI(TAG, "Cannot initialize i2c driver. Error = %d", res);
    // test for normal mode
        bmp_data_t bmpdata;
        while(1 && res == BMP2_OK)
            vTaskDelay(2000 / portTICK_PERIOD_MS); //wait 2 seconds

    and here is some sample log

    I (02:00:02.675) WESTA OP: bmp280 chip ID: 58 4 4 0 5 2 0
    I (02:00:02.676) WESTA OP: bmp280 cal param:  27117  26189
     34962 -10618   3024   3525    234
        -7  15500 -14600   6000      0
    I (02:00:02.680) WESTA OP: bmp280 config: 4 4  5 2  0
    I (02:00:02.682) WESTA OP: bmp280 power mode: 3
    I (02:00:02.684) WESTA OP: Temperature =   28.135
    I (02:00:02.685) WESTA OP: Pressure    = 83878.021
    I (02:00:05.832) WESTA OP: Temperature =   28.135
    I (02:00:05.834) WESTA OP: Pressure    = 83878.021
    I (11:55:39.467) NTP sync: Notification of a time synchronization event
    I (11:55:39.757) NTP sync: local time updated 2023-04-06/11:55:39
    I (11:52:27.952) WESTA OP: Temperature =   28.135
    I (11:52:27.953) WESTA OP: Pressure    = 83878.021
    I (11:52:29.952) WESTA OP: Temperature =   28.135
    I (11:52:29.953) WESTA OP: Pressure    = 83878.021
    I (11:52:31.952) WESTA OP: Temperature =   28.135
    I (11:52:31.953) WESTA OP: Pressure    = 83878.021
    I (11:52:33.952) WESTA OP: Temperature =   28.135
    I (11:52:33.953) WESTA OP: Pressure    = 83878.021
    I (11:52:35.952) WESTA OP: Temperature =   28.135
    I (11:52:35.953) WESTA OP: Pressure    = 83878.021
    I (11:52:37.952) WESTA OP: Temperature =   28.135