Skip to content

Commit 052d676

Browse files
committed
fix hang due to powerdown of ths221 sensor
fix the hangs due to consecutive HTS221 readings
1 parent fed32b8 commit 052d676

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/MKRENV.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ int ENVClass::begin()
8686

8787
readHTS221Calibration();
8888

89-
// enable HTS221
90-
i2cWrite(HTS221_ADDRESS, HTS221_CTRL1_REG, 0x80);
89+
// turn on the HTS221 and enable Block Data Update
90+
i2cWrite(HTS221_ADDRESS, HTS221_CTRL1_REG, 0x84);
9191

9292
// configure VEML6075 for 100 ms
9393
i2cWriteWord(VEML6075_ADDRESS, VEML6075_UV_CONF_REG, 0x0010);
@@ -111,6 +111,9 @@ void ENVClass::end()
111111

112112
float ENVClass::readTemperature(int units)
113113
{
114+
// Wait for ONE_SHOT bit to be cleared by the hardware
115+
while (i2cRead(HTS221_ADDRESS, HTS221_CTRL2_REG) & 0x01);
116+
114117
// trigger one shot
115118
i2cWrite(HTS221_ADDRESS, HTS221_CTRL2_REG, 0x01);
116119

@@ -131,6 +134,9 @@ float ENVClass::readTemperature(int units)
131134

132135
float ENVClass::readHumidity()
133136
{
137+
//Wait for ONE_SHOT bit to be cleared by the hardware
138+
while (i2cRead(HTS221_ADDRESS, HTS221_CTRL2_REG) & 0x01);
139+
134140
// trigger one shot
135141
i2cWrite(HTS221_ADDRESS, HTS221_CTRL2_REG, 0x01);
136142

0 commit comments

Comments
 (0)