From 3c01fdebbb9cbe8a7ff24575a2c161f971115366 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 3 Nov 2020 15:20:17 +0100 Subject: [PATCH] Wire: Let requestFrom return the number of available bytes Previously, it would return the number of requested bytes, even if the slave returned a NAK on the address byte, preventing libraries to detect such a NAK. For example, the SparkFun HTU21D library would fail to read humidity, because the "I'm not ready measuring"-NAK would look like a successful read, but with dummy data. This matches the return value with that of the official Arduino versions and the documentation at https://www.arduino.cc/en/Reference/WireRequestFrom --- libraries/Wire/src/Wire.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 7e1b2038..7f93e6c6 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -229,7 +229,7 @@ size_t TwoWire::requestFrom(uint8_t address, size_t size, bool stopBit) _rx_write = size; } - return size; + return _rx_write; } size_t TwoWire::write(uint8_t data)