From f0b5911d0a38e0f930738e89c27340db1ff24044 Mon Sep 17 00:00:00 2001 From: Filip Stojanovic Date: Sun, 6 Jul 2025 18:13:32 +0200 Subject: [PATCH] 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 --- drivers/sensor/bosch/bme280/bme280.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/sensor/bosch/bme280/bme280.c b/drivers/sensor/bosch/bme280/bme280.c index a1990e3d14d..05566104ce6 100644 --- a/drivers/sensor/bosch/bme280/bme280.c +++ b/drivers/sensor/bosch/bme280/bme280.c @@ -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);