Commit f0b5911d authored by Filip Stojanovic's avatar Filip Stojanovic Committed by Daniel DeGrasse
Browse files

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: default avatarFilip Stojanovic <filipembedded@gmail.com>
parent 9245f58b
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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);