From c009450d4476a74a030dd7fd08b74d2fea78907c Mon Sep 17 00:00:00 2001 From: Efrain Calderon Date: Tue, 27 Jul 2021 19:34:04 +0200 Subject: [PATCH] drivers: bme280: do soft reset after boot To ensure that we have the same behaviour with a power cycle and by pressing the reset button, we can perform soft reset in `bme280_chip_init()`. Signed-off-by: Efrain Calderon --- drivers/sensor/bme280/bme280.c | 8 ++++++++ drivers/sensor/bme280/bme280.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/drivers/sensor/bme280/bme280.c b/drivers/sensor/bme280/bme280.c index b00e293bf15..c1372af2c29 100644 --- a/drivers/sensor/bme280/bme280.c +++ b/drivers/sensor/bme280/bme280.c @@ -353,6 +353,12 @@ static int bme280_chip_init(const struct device *dev) return -ENOTSUP; } + err = bme280_reg_write(dev, BME280_REG_RESET, BME280_CMD_SOFT_RESET); + if (err < 0) { + LOG_DBG("Soft-reset failed: %d", err); + return err; + } + err = bme280_read_compensation(dev); if (err < 0) { return err; @@ -380,6 +386,8 @@ static int bme280_chip_init(const struct device *dev) LOG_DBG("CONFIG write failed: %d", err); return err; } + /* Wait for the sensor to be ready */ + k_sleep(K_MSEC(1)); #ifdef CONFIG_PM_DEVICE /* Set power state to ACTIVE */ diff --git a/drivers/sensor/bme280/bme280.h b/drivers/sensor/bme280/bme280.h index 7ef1c934489..9aa6e175376 100644 --- a/drivers/sensor/bme280/bme280.h +++ b/drivers/sensor/bme280/bme280.h @@ -63,6 +63,7 @@ extern const struct bme280_bus_io bme280_bus_io_i2c; #define BME280_REG_CTRL_MEAS 0xF4 #define BME280_REG_CTRL_HUM 0xF2 #define BME280_REG_STATUS 0xF3 +#define BME280_REG_RESET 0xE0 #define BMP280_CHIP_ID_SAMPLE_1 0x56 #define BMP280_CHIP_ID_SAMPLE_2 0x57 @@ -72,6 +73,7 @@ extern const struct bme280_bus_io bme280_bus_io_i2c; #define BME280_MODE_FORCED 0x01 #define BME280_MODE_NORMAL 0x03 #define BME280_SPI_3W_DISABLE 0x00 +#define BME280_CMD_SOFT_RESET 0xB6 #if defined CONFIG_BME280_MODE_NORMAL #define BME280_MODE BME280_MODE_NORMAL