aboutsummaryrefslogtreecommitdiff
path: root/libraries/Wire/utility
diff options
context:
space:
mode:
authorSandeep Mistry <s.mistry@arduino.cc>2015-08-28 10:25:56 -0400
committerCristian Maglie <c.maglie@arduino.cc>2015-10-22 16:33:00 +0200
commit02dcc6ec74469523f2dc5502b1900bdf927ee1a3 (patch)
tree32218868cb253d61532391d5f58c6d8b2ef92b41 /libraries/Wire/utility
parent48bcef5a15f1b17aee877bdb8cf77c6b45faaa6e (diff)
check TWWC (Write Collision Flag) bit after setting TWDR
as suggested by @earlyprogrammer in #2173, to ensure TWDR value is set if there is a write collision
Diffstat (limited to 'libraries/Wire/utility')
-rw-r--r--libraries/Wire/utility/twi.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libraries/Wire/utility/twi.c b/libraries/Wire/utility/twi.c
index 9fb87f1..2af0597 100644
--- a/libraries/Wire/utility/twi.c
+++ b/libraries/Wire/utility/twi.c
@@ -167,7 +167,9 @@ uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sen
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent outselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
- TWDR = twi_slarw;
+ do {
+ TWDR = twi_slarw;
+ } while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
}
else
@@ -247,7 +249,9 @@ uint8_t twi_writeTo(uint8_t address, uint8_t* data, uint8_t length, uint8_t wait
// up. Also, don't enable the START interrupt. There may be one pending from the
// repeated start that we sent outselves, and that would really confuse things.
twi_inRepStart = false; // remember, we're dealing with an ASYNC ISR
- TWDR = twi_slarw;
+ do {
+ TWDR = twi_slarw;
+ } while(TWCR & _BV(TWWC));
TWCR = _BV(TWINT) | _BV(TWEA) | _BV(TWEN) | _BV(TWIE); // enable INTs, but not START
}
else