Skip to content

Commit 0f309b2

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 0f309b2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/HTS.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ int HTS221Class::begin()
5656

5757
readHTS221Calibration();
5858

59-
// enable HTS221
60-
i2cWrite(HTS221_CTRL1_REG, 0x80);
59+
// turn on the HTS221 and enable Block Data Update
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 ONE_SHOT bit to be cleared by the hardware
76+
while (i2cRead(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 ONE_SHOT bit to be cleared by the hardware
99+
while (i2cRead(HTS221_CTRL2_REG) & 0x01);
100+
95101
// trigger one shot
96102
i2cWrite(HTS221_CTRL2_REG, 0x01);
97103

0 commit comments

Comments
 (0)