Skip to content

Commit eb7cc68

Browse files
committed
Fixed hang due to consecutive read tempurature
fix the hang issue due to consecutive reads of the temperature register porting of arduino-libraries/Arduino_MKRENV#6
1 parent 990f981 commit eb7cc68

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/HTS.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int HTS221Class::begin()
5757
readHTS221Calibration();
5858

5959
// enable HTS221
60-
i2cWrite(HTS221_CTRL1_REG, 0x80);
60+
i2cWrite(HTS221_CTRL1_REG, 0x84);
6161

6262
return 1;
6363
}
@@ -72,6 +72,9 @@ void HTS221Class::end()
7272

7373
float HTS221Class::readTemperature(int units)
7474
{
75+
// Wait for trigger a new read operation
76+
while (HTS221_CTRL2_REG) & 0x01);
77+
7578
// trigger one shot
7679
i2cWrite(HTS221_CTRL2_REG, 0x01);
7780

@@ -92,6 +95,9 @@ float HTS221Class::readTemperature(int units)
9295

9396
float HTS221Class::readHumidity()
9497
{
98+
// Wait for trigger a new read operation
99+
while (HTS221_CTRL2_REG) & 0x01);
100+
95101
// trigger one shot
96102
i2cWrite(HTS221_CTRL2_REG, 0x01);
97103

@@ -102,8 +108,8 @@ float HTS221Class::readHumidity()
102108

103109
// read value and convert
104110
int16_t hout = i2cRead16(HTS221_HUMIDITY_OUT_L_REG);
105-
106-
return (hout * _hts221HumiditySlope + _hts221HumidityZero);
111+
float reading = hout * _hts221HumiditySlope + _hts221HumidityZero;
112+
return reading;
107113
}
108114

109115
int HTS221Class::i2cRead(uint8_t reg)

0 commit comments

Comments
 (0)