Skip to content

Commit 43d5e07

Browse files
committed
Fix buffer being overwritten by multiple twi_transmit calls
Fixes that more complex methods (like Stream::print(float)) do not work properly. Without this fix, Wire.print(1.01f); results in '1' because Print::printFloat(double, uint8_t) performs multiple print() and therefore twi_transmit calls. Also Wire.println("Heyho"); results only in a newline character.
1 parent cc4ddc3 commit 43d5e07

File tree

1 file changed

+3
-3
lines changed
  • libraries/Wire/src/utility

1 file changed

+3
-3
lines changed

Diff for: libraries/Wire/src/utility/twi.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length)
304304
uint8_t i;
305305

306306
// ensure data will fit into buffer
307-
if(TWI_BUFFER_LENGTH < length){
307+
if(TWI_BUFFER_LENGTH < (twi_txBufferLength+length)){
308308
return 1;
309309
}
310310

@@ -314,10 +314,10 @@ uint8_t twi_transmit(const uint8_t* data, uint8_t length)
314314
}
315315

316316
// set length and copy data into tx buffer
317-
twi_txBufferLength = length;
318317
for(i = 0; i < length; ++i){
319-
twi_txBuffer[i] = data[i];
318+
twi_txBuffer[twi_txBufferLength+i] = data[i];
320319
}
320+
twi_txBufferLength += length;
321321

322322
return 0;
323323
}

0 commit comments

Comments
 (0)