Skip to content

Commit d23c1d0

Browse files
committed
Nicla Sense: protect BQ read operation with timeout
1 parent 3396b0e commit d23c1d0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libraries/Nicla_System/src/pmic_driver.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ uint8_t BQ25120A::readByte(uint8_t address, uint8_t subAddress)
2727
Wire1.write(subAddress);
2828
Wire1.endTransmission(false);
2929
Wire1.requestFrom(address, 1);
30-
while(!Wire1.available()) {}
30+
uint32_t timeout = 1000;
31+
uint32_t start_time = millis();
32+
while(!Wire1.available() && (millis() - start_time) < timeout) {}
3133
uint8_t ret = Wire1.read();
3234
nicla::i2c_mutex.unlock();
3335
return ret;

0 commit comments

Comments
 (0)