sensor: bme280: Fix bad chip id read after power cycle

Fix an issue where the BME280 sometimes returns an incorrect chip ID
immediately after a power cycle. This causes sensor initialization to fail.

According to the datasheet, the sensor requires a 2 ms start-up delay after
power is applied. This patch introduces a sleep delay to ensure the
required start-up time is respected before reading the chip ID.

Signed-off-by: Filip Stojanovic <filipembedded@gmail.com>
This commit is contained in:
Filip Stojanovic 2025-07-06 18:13:32 +02:00 committed by Daniel DeGrasse
parent 9245f58b4c
commit f0b5911d0a

View File

@ -33,6 +33,11 @@ LOG_MODULE_REGISTER(BME280, CONFIG_SENSOR_LOG_LEVEL);
*/
#define BME280_MEASUREMENT_TIMEOUT_MS 150
/* Start-up time - Time to first communication after both Vdd > 1.58V and
* Vddio > 0.65V
*/
#define BME280_START_UP_TIME_MS 2
/* Equation 9.1, with the fractional parts rounded down */
#define BME280_EXPECTED_SAMPLE_TIME_MS \
1 + BME280_TEMP_SAMPLE_TIME + BME280_PRESS_SAMPLE_TIME + BME280_HUMIDITY_SAMPLE_TIME
@ -332,6 +337,8 @@ static int bme280_chip_init(const struct device *dev)
return err;
}
k_msleep(BME280_START_UP_TIME_MS);
err = bme280_reg_read(dev, BME280_REG_ID, &data->chip_id, 1);
if (err < 0) {
LOG_DBG("ID read failed: %d", err);