Skip to content

Commit f376316

Browse files
authored
WireMaster example clarity (espressif#6844)
- Created new temporary variable, stopping confusion with the reuse of "error". As Wire.requestFrom() doesn't return an error. - Added a cast to help clarify when and why bytes are being read
1 parent 53698ae commit f376316

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

libraries/Wire/examples/WireMaster/WireMaster.ino

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ void loop() {
2020
Serial.printf("endTransmission: %u\n", error);
2121

2222
//Read 16 bytes from the slave
23-
error = Wire.requestFrom(I2C_DEV_ADDR, 16);
24-
Serial.printf("requestFrom: %u\n", error);
25-
if(error){
26-
uint8_t temp[error];
27-
Wire.readBytes(temp, error);
28-
log_print_buf(temp, error);
23+
uint8_t bytesReceived = Wire.requestFrom(I2C_DEV_ADDR, 16);
24+
Serial.printf("requestFrom: %u\n", bytesReceived);
25+
if((bool)bytesReceived){ //If received more than zero bytes
26+
uint8_t temp[bytesReceived];
27+
Wire.readBytes(temp, bytesReceived);
28+
log_print_buf(temp, bytesReceived);
2929
}
3030
}

0 commit comments

Comments
 (0)