Skip to content

Commit 0df27f6

Browse files
committed
Nicla_System: exit from RGBled::readByte() if 100ms timeout expires
1 parent afbfbca commit 0df27f6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libraries/Nicla_System/src/RGBled.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ uint8_t RGBled::readByte(uint8_t address, uint8_t subAddress)
160160
Wire1.write(subAddress);
161161
Wire1.endTransmission(false);
162162
Wire1.requestFrom(address, 1);
163-
while(!Wire1.available()) {}
163+
uint32_t timeout = 100;
164+
uint32_t start_time = millis();
165+
while(!Wire1.available() && (millis() - start_time) < timeout) {}
164166
uint8_t ret = Wire1.read();
165167
nicla::i2c_mutex.unlock();
166168
return ret;

0 commit comments

Comments
 (0)