Skip to content

Commit f6beb3d

Browse files
committed
Fixed Wire.write() always returning 0 in slave send mode
1 parent 4a0324a commit f6beb3d

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,21 @@ size_t TwoWire::write(uint8_t data)
264264
// or after beginTransmission(address)
265265
size_t TwoWire::write(const uint8_t *data, size_t quantity)
266266
{
267-
// number of bytes successfully added to the buffer
268-
uint8_t bytesSent = 0;
269267
if(transmitting){
270-
// in master transmitter mode
268+
// in master transmitter mode
269+
uint8_t bytesSent = 0;
270+
// number of bytes successfully added to the buffer
271271
for(size_t i = 0; i < quantity; ++i){
272272
if (write(data[i]) == 1) // if a byte was successfully added to the buffer
273273
bytesSent++;
274-
}
274+
}
275+
return bytesSent;
275276
}else{
276277
// in slave send mode
277278
// reply to master
278279
twi_transmit(data, quantity);
280+
return quantity;
279281
}
280-
return bytesSent;
281282
}
282283

283284
// must be called in:

0 commit comments

Comments
 (0)