Skip to content

Commit 685820f

Browse files
committed
Wire: Fix write() returning incorrect byte count on buffer overflow (see issue #597)
fixed typo Fixed Wire.write() always returning 0 in slave send mode
1 parent 62da873 commit 685820f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,20 @@ size_t TwoWire::write(uint8_t data)
265265
size_t TwoWire::write(const uint8_t *data, size_t quantity)
266266
{
267267
if(transmitting){
268-
// in master transmitter mode
268+
// in master transmitter mode
269+
uint8_t bytesSent = 0;
270+
// number of bytes successfully added to the buffer
269271
for(size_t i = 0; i < quantity; ++i){
270-
write(data[i]);
271-
}
272+
if (write(data[i]) == 1) // if a byte was successfully added to the buffer
273+
bytesSent++;
274+
}
275+
return bytesSent;
272276
}else{
273277
// in slave send mode
274278
// reply to master
275279
twi_transmit(data, quantity);
280+
return quantity;
276281
}
277-
return quantity;
278282
}
279283

280284
// must be called in:

0 commit comments

Comments
 (0)