aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire/utility/twi.c
diff options
context:
space:
mode:
authorDavid A. Mellis <d.mellis@arduino.cc>2009-06-20 20:43:24 +0000
committerDavid A. Mellis <d.mellis@arduino.cc>2009-06-20 20:43:24 +0000
commit6b62b244d51d93f670c6f9e80ba92da3aceff947 (patch)
tree0326f05a8e7803cc9678886abdda835d4d406867 /libraries/Wire/utility/twi.c
parentc3baee9f63f7876bb30d128ee6e59cc0266312a9 (diff)
Fixing bug in Wire library that caused it to read and discard one extra byte when do a requestFrom() a slave device. Thanks to Christopher K. Johnson.
Diffstat (limited to 'libraries/Wire/utility/twi.c')
-rw-r--r--libraries/Wire/utility/twi.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libraries/Wire/utility/twi.c b/libraries/Wire/utility/twi.c
index 82a25c0..bfa917a 100644
--- a/libraries/Wire/utility/twi.c
+++ b/libraries/Wire/utility/twi.c
@@ -135,7 +135,12 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length)
// initialize buffer iteration vars
twi_masterBufferIndex = 0;
- twi_masterBufferLength = length;
+ twi_masterBufferLength = length-1; // This is not intuitive, read on...
+ // On receive, the previously configured ACK/NACK setting is transmitted in
+ // response to the received byte before the interrupt is signalled.
+ // Therefor we must actually set NACK when the _next_ to last byte is
+ // received, causing that NACK to be sent in response to receiving the last
+ // expected byte of data.
// build sla+w, slave device address + w bit
twi_slarw = TW_READ;