Skip to content

Commit 6aae53b

Browse files
filipembeddedseyoungjeong
authored andcommitted
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>
1 parent aa0237b commit 6aae53b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/sensor/bosch/bme280/bme280.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ LOG_MODULE_REGISTER(BME280, CONFIG_SENSOR_LOG_LEVEL);
3333
*/
3434
#define BME280_MEASUREMENT_TIMEOUT_MS 150
3535

36+
/* Start-up time - Time to first communication after both Vdd > 1.58V and
37+
* Vddio > 0.65V
38+
*/
39+
#define BME280_START_UP_TIME_MS 2
40+
3641
/* Equation 9.1, with the fractional parts rounded down */
3742
#define BME280_EXPECTED_SAMPLE_TIME_MS \
3843
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)
332337
return err;
333338
}
334339

340+
k_msleep(BME280_START_UP_TIME_MS);
341+
335342
err = bme280_reg_read(dev, BME280_REG_ID, &data->chip_id, 1);
336343
if (err < 0) {
337344
LOG_DBG("ID read failed: %d", err);

0 commit comments

Comments
 (0)