diff --git a/Adafruit_BME280.cpp b/Adafruit_BME280.cpp index 7b9c0ec..ce21cf2 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; + // 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(); // read trimming parameters, see DS 4.2.2 - + setSampling(); // use defaults return true; @@ -303,7 +314,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); } } @@ -337,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);