Skip to content

Commit d239b1b

Browse files
Filip StojanovicChromeos LUCI
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. (cherry picked from commit f0b5911) Original-Signed-off-by: Filip Stojanovic <[email protected]> GitOrigin-RevId: f0b5911 Cr-Build-Id: 8709847665304561137 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8709847665304561137 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I7709451108540ab565f41ca5457b42af2e4caeff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6717681 Commit-Queue: ChromeOS Copybot <[email protected]> Tested-by: ChromeOS Copybot <[email protected]> Bot-Commit: ChromeOS Copybot <[email protected]>
1 parent 90e2f3b commit d239b1b

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)