From 4f66f97fe6f5e3e05fa12fc3df0f6411016aa4b8 Mon Sep 17 00:00:00 2001 From: pm73 Date: Wed, 8 Feb 2017 12:32:22 +0100 Subject: [PATCH 1/3] change loop to delay so ESP8266 can do Wi-Fi tasks delay(1) allows ESP8266 to do Wi-Fi tasks. It is recommended to not make any code that blocks this for more than 20/50 microseconds. --- Adafruit_BME280.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 7b9c0ec..d36f0c2 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -303,7 +303,8 @@ void Adafruit_BME280::takeForcedMeasurement() write8(BME280_REGISTER_CONTROL, _measReg.get()); // wait until measurement has been completed, otherwise we would read // the values from the last measurement - while (read8(BME280_REGISTER_STATUS) & 0x08); + while (read8(BME280_REGISTER_STATUS) & 0x08) + delay(1); } } From 50fb31ace1274d82ddf22a665d6c6ba38dea03e4 Mon Sep 17 00:00:00 2001 From: Frank Leon Rose Date: Thu, 9 Feb 2017 10:21:13 -0500 Subject: [PATCH 2/3] On begin, read coefficients after calibration --- Adafruit_BME280.cpp | 27 +++++++++++++++++++++++++-- Adafruit_BME280.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index d36f0c2..934be6b 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -66,8 +66,19 @@ bool Adafruit_BME280::begin(uint8_t addr) if (read8(BME280_REGISTER_CHIPID) != 0x60) return false; - readCoefficients(); // read trimming parameters, see DS 4.2.2 - + // reset the device using soft-reset + // this makes sure the IIR is off, etc. + write8(BME280_REGISTER_SOFTRESET, 0xB6); + + // wait for chip to wake up. + delay(300); + + // if chip is still reading calibration, delay + while (isReadingCalibration()) + delay(100); + + readCoefficients(); + setSampling(); // use defaults return true; @@ -338,6 +349,18 @@ void Adafruit_BME280::readCoefficients(void) _bme280_calib.dig_H6 = (int8_t)read8(BME280_REGISTER_DIG_H6); } +/**************************************************************************/ +/*! + @brief return true if chip is busy reading cal data +*/ +/**************************************************************************/ +bool Adafruit_BME280::isReadingCalibration(void) +{ + uint8_t const rStatus = read8(BME280_REGISTER_STATUS); + + return (rStatus & (1 << 0)) != 0; +} + /**************************************************************************/ /*! diff --git a/Adafruit_BME280.h b/Adafruit_BME280.h index 9bbd676..a0de5f7 100644 --- a/Adafruit_BME280.h +++ b/Adafruit_BME280.h @@ -187,6 +187,7 @@ class Adafruit_BME280 { private: void readCoefficients(void); + bool isReadingCalibration(void); uint8_t spixfer(uint8_t x); void write8(byte reg, byte value); From b72b7d6285a0bc38a50c75ea3f7556c0e9e09566 Mon Sep 17 00:00:00 2001 From: Frank Leon Rose Date: Thu, 9 Feb 2017 10:34:19 -0500 Subject: [PATCH 3/3] Restore comment --- Adafruit_BME280.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 934be6b..ce21cf2 100644 --- a/Adafruit_BME280.cpp +++ b/Adafruit_BME280.cpp @@ -77,7 +77,7 @@ bool Adafruit_BME280::begin(uint8_t addr) while (isReadingCalibration()) delay(100); - readCoefficients(); + readCoefficients(); // read trimming parameters, see DS 4.2.2 setSampling(); // use defaults