04-04-2023 10:53 AM
Hello
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 https://github.com/boschsensortec/BMP2-Sensor-API, ported for ESP32.
I'm aware about the old topic https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMP280-Always-initial-values/m-p/27791#M... 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
The configuration i use is this one:
conf.os_mode = BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
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?
Regards
Ves011
Solved! Go to Solution.
04-07-2023 02:09 AM
Hi Ves011,
Do you have any intention to set oversampling indepently not to call set_config function?
If not, would you remove samping setting in get_bmp_data function and call bmp2_set_config before bmp2_set_power_mode?
rslt = bmp2_init(&dev);
bmp2_error_codes_print_result("bmp2_init", rslt);
/* Always read the current settings before writing, especially when all the configuration is not modified */
rslt = bmp2_get_config(&conf, &dev);
bmp2_error_codes_print_result("bmp2_get_config", rslt);
/* Configuring the over-sampling mode, filter coefficient and output data rate */
/* Overwrite the desired settings */
conf.filter = BMP2_FILTER_OFF;
/* Over-sampling mode is set as high resolution i.e., os_pres = 8x and os_temp = 1x */
conf.os_mode = BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.filter = BMP2_FILTER_COEFF_16;
conf.os_pres = 5; // BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.os_temp = 2; //BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.odr = BMP2_ODR_500_MS;
rslt = bmp2_set_config(&conf, &dev);
bmp2_error_codes_print_result("bmp2_set_config", rslt);
/* Set normal power mode */
rslt = bmp2_set_power_mode(BMP2_POWERMODE_NORMAL, &conf, &dev);
bmp2_error_codes_print_result("bmp2_set_power_mode", rslt);
Thank you.
04-07-2023 08:48 AM
Hi Minhwan
I added in the code your suggestions and it looks like this
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);
//suggested modification
conf.filter = BMP2_FILTER_OFF;
//----------------------------
conf.os_mode = BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.filter = BMP2_FILTER_COEFF_16;
conf.os_pres = 5; // BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.os_temp = 2; //BMP2_OS_MODE_ULTRA_HIGH_RESOLUTION;
conf.odr = BMP2_ODR_500_MS;
//suggested modification
res = bmp2_set_config(&conf, &bmpdev);
//------------------------------------
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);
}
else
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)
{
get_bmp_data(&bmpdata);
vTaskDelay(2000 / portTICK_PERIOD_MS); //wait 2 seconds
}
Hope i didn't miss anything.
But the result is the same
I (02:00:02.621) WESTA OP: bmp280 chip ID: 58 4 4 f4 5 2 0
I (02:00:02.622) WESTA OP: bmp280 cal param: 27117 26189
34962 -10618 3024 3525 234
-7 15500 -14600 6000 0
I (02:00:02.628) WESTA OP: bmp280 config: 4 4 5 2 0
I (02:00:02.629) WESTA OP: bmp280 power mode: 3
I (02:00:02.631) WESTA OP: Temperature = 28.135
I (02:00:02.633) WESTA OP: Pressure = 83878.021
I (09:37:29.107) WESTA OP: Temperature = 28.135
I (09:37:29.108) WESTA OP: Pressure = 83878.021
I (09:37:31.107) WESTA OP: Temperature = 28.135
I (09:37:31.108) WESTA OP: Pressure = 83878.021
I (09:37:33.107) WESTA OP: Temperature = 28.135
I (09:37:33.108) WESTA OP: Pressure = 83878.021
I (09:37:35.107) WESTA OP: Temperature = 28.135
I (09:37:35.108) WESTA OP: Pressure = 83878.021
I (09:37:37.107) WESTA OP: Temperature = 28.135
I (09:37:37.108) WESTA OP: Pressure = 83878.021
I (09:37:39.107) WESTA OP: Temperature = 28.135
I (09:37:39.108) WESTA OP: Pressure = 83878.021
I (09:37:41.107) WESTA OP: Temperature = 28.135
I (09:37:41.108) WESTA OP: Pressure = 83878.021
I (09:37:43.107) WESTA OP: Temperature = 28.135
I (09:37:43.108) WESTA OP: Pressure = 83878.021
I (09:37:45.107) WESTA OP: Temperature = 28.135
I (09:37:45.108) WESTA OP: Pressure = 83878.021
I (09:37:47.107) WESTA OP: Temperature = 28.135
I (09:37:47.108) WESTA OP: Pressure = 83878.021
I (09:37:49.107) WESTA OP: Temperature = 28.135
04-07-2023 11:06 PM
Hi @ves011,
Your setting looks okay.
And you said, forced mode is okay. So, let's get some data as we set.
Could you clean up your get bmp data as below and change sleep to 500ms?
static int get_bmp_data(bmp_data_t *bmpdata)
{
int res = 0;
struct bmp2_status bmps;
while((res = bmp2_get_status(&bmps, &bmpdev) == BMP2_OK) && bmps.measuring == 1)
{
vTaskDelay(pdMS_TO_TICKS(10));
//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;
}
And please share the result.
Thanks,
04-08-2023 11:29 AM
Hi @Minhwan
Did the clean-up requested like this
static int get_bmp_data(bmp_data_t *bmpdata)
{
int res = BMP2_E_COM_FAIL;
struct bmp2_status bmps;
while((res = bmp2_get_status(&bmps, &bmpdev) == BMP2_OK) && bmps.measuring == 1)
{
vTaskDelay(pdMS_TO_TICKS(10));
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/100.);
//sprintf(buf, "BMP\1%.3f\1%.3f", bmpdata->temperature, bmpdata->pressure);
//publish_state(buf, 0, 0);
}
return res;
}
I kept the "bmp280 busy" log to see if it is ever hit.
The result is the same.
I (02:00:03.868) WESTA OP: bmp280 chip ID: 58 4 4 c0 5 2 0
I (02:00:03.869) WESTA OP: bmp280 cal param: 27117 26189
34962 -10618 3024 3525 234
-7 15500 -14600 6000 0
I (02:00:03.874) WESTA OP: bmp280 config: 4 4 5 2 0
I (02:00:03.875) WESTA OP: bmp280 power mode: 3
I (02:00:03.877) WESTA OP: Temperature = 28.135
I (02:00:03.878) WESTA OP: Pressure = 838.780
W (5373) wifi:<ba-add>idx:1 (ifx:0, 5c:a6:e6:f0:a9:27), tid:7, ssn:0, winSize:64
I (02:00:04.652) NTP sync: Waiting for system time to be set... (3/100)
I (02:00:05.652) NTP sync: Waiting for system time to be set... (4/100)
I (02:00:05.873) WESTA OP: Temperature = 28.135
I (02:00:05.874) WESTA OP: Pressure = 838.780
I (02:00:06.652) NTP sync: Waiting for system time to be set... (5/100)
I (11:49:19.383) NTP sync: Notification of a time synchronization event
I (11:49:19.898) NTP sync: local time updated 2023-04-08/11:49:19
I (11:49:20.120) WESTA OP: Temperature = 28.135
I (11:49:20.121) WESTA OP: Pressure = 838.780
I (11:49:22.120) WESTA OP: Temperature = 28.135
I (11:49:22.121) WESTA OP: Pressure = 838.780
I (11:49:24.120) WESTA OP: Temperature = 28.135
I (11:49:24.121) WESTA OP: Pressure = 838.780
I (11:49:26.120) WESTA OP: Temperature = 28.135
I (11:49:26.121) WESTA OP: Pressure = 838.780
I (11:49:28.120) WESTA OP: Temperature = 28.135
I (11:49:28.121) WESTA OP: Pressure = 838.780
I (11:49:30.120) WESTA OP: Temperature = 28.135
I (11:49:30.121) WESTA OP: Pressure = 838.780
I (11:49:32.120) WESTA OP: Temperature = 28.135
I (11:49:32.121) WESTA OP: Pressure = 838.780
I (11:49:34.120) WESTA OP: Temperature = 28.135
I (11:49:34.121) WESTA OP: Pressure = 838.780
I (11:49:36.120) WESTA OP: Temperature = 28.135
I (11:49:36.121) WESTA OP: Pressure = 838.780
I (11:49:38.120) WESTA OP: Temperature = 28.135
I (11:49:38.121) WESTA OP: Pressure = 838.780
I (11:49:40.120) WESTA OP: Temperature = 28.135
I (11:49:40.121) WESTA OP: Pressure = 838.780
I let it run for more than half hour to see if "bmp280 busy" is hit, but it didn't
Want to remember my coment in the first post in this thread: if system goes over power cycle (remove power/insert power) it works perfect. But after reset (hard or soft) it goes into this issue.
Here is a log after power cycle
I (02:00:03.833) WESTA OP: bmp280 chip ID: 58 0 0 c0 0 0 0
I (02:00:03.834) WESTA OP: bmp280 cal param: 27117 26189
34962 -10618 3024 3525 234
-7 15500 -14600 6000 0
I (02:00:03.838) WESTA OP: bmp280 config: 4 4 5 2 0
I (02:00:03.839) WESTA OP: bmp280 power mode: 3
I (02:00:03.850) WESTA OP: bmp280 busy
I (02:00:03.860) WESTA OP: bmp280 busy
I (02:00:03.870) WESTA OP: bmp280 busy
I (02:00:03.880) WESTA OP: bmp280 busy
I (02:00:03.882) WESTA OP: Temperature = 23.795
I (02:00:03.883) WESTA OP: Pressure = 1011.447
W (5501) wifi:<ba-add>idx:1 (ifx:0, 5c:a6:e6:f0:a9:27), tid:7, ssn:1, winSize:64
I (02:00:04.620) NTP sync: Waiting for system time to be set... (3/100)
I (02:00:05.620) NTP sync: Waiting for system time to be set... (4/100)
I (02:00:05.881) WESTA OP: Temperature = 23.800
I (02:00:05.882) WESTA OP: Pressure = 1011.465
I (11:47:45.941) NTP sync: Notification of a time synchronization event
I (11:47:46.361) NTP sync: local time updated 2023-04-08/11:47:46
I (11:47:47.622) WESTA OP: Temperature = 23.803
I (11:47:47.623) WESTA OP: Pressure = 1011.474
I (11:47:49.622) WESTA OP: Temperature = 23.803
I (11:47:49.623) WESTA OP: Pressure = 1011.481
I (11:47:51.622) WESTA OP: Temperature = 23.800
I (11:47:51.623) WESTA OP: Pressure = 1011.489
I (11:47:53.622) WESTA OP: Temperature = 23.800
I (11:47:53.623) WESTA OP: Pressure = 1011.501
As you can see i get expected values and "bmp280 busy" is hit several times
04-21-2023 11:18 PM
Hi Ves022,
2ms delay after soft reset is required.
Our API will be updated in next version up.
Please let me know if you have any questions.
Thank you.