Skip to content

Commit f1e1490

Browse files
authored
Merge pull request #20 from things-nyc/fix-await-calibration
Reset on begin and read coefficients only after calibration
2 parents f741893 + b72b7d6 commit f1e1490

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Adafruit_BME280.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,19 @@ bool Adafruit_BME280::begin(uint8_t addr)
6666
if (read8(BME280_REGISTER_CHIPID) != 0x60)
6767
return false;
6868

69+
// reset the device using soft-reset
70+
// this makes sure the IIR is off, etc.
71+
write8(BME280_REGISTER_SOFTRESET, 0xB6);
72+
73+
// wait for chip to wake up.
74+
delay(300);
75+
76+
// if chip is still reading calibration, delay
77+
while (isReadingCalibration())
78+
delay(100);
79+
6980
readCoefficients(); // read trimming parameters, see DS 4.2.2
70-
81+
7182
setSampling(); // use defaults
7283

7384
return true;
@@ -338,6 +349,18 @@ void Adafruit_BME280::readCoefficients(void)
338349
_bme280_calib.dig_H6 = (int8_t)read8(BME280_REGISTER_DIG_H6);
339350
}
340351

352+
/**************************************************************************/
353+
/*!
354+
@brief return true if chip is busy reading cal data
355+
*/
356+
/**************************************************************************/
357+
bool Adafruit_BME280::isReadingCalibration(void)
358+
{
359+
uint8_t const rStatus = read8(BME280_REGISTER_STATUS);
360+
361+
return (rStatus & (1 << 0)) != 0;
362+
}
363+
341364

342365
/**************************************************************************/
343366
/*!

Adafruit_BME280.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class Adafruit_BME280 {
187187

188188
private:
189189
void readCoefficients(void);
190+
bool isReadingCalibration(void);
190191
uint8_t spixfer(uint8_t x);
191192

192193
void write8(byte reg, byte value);

0 commit comments

Comments
 (0)