Skip to content

Commit a4e79c9

Browse files
Merge pull request firmata#450 from pgrawehr/I2CReplyLength
Return only as many bytes as were received in I2C transfers.
2 parents e5204be + 9eac4a8 commit a4e79c9

File tree

6 files changed

+6
-0
lines changed

6 files changed

+6
-0
lines changed

examples/StandardFirmata/StandardFirmata.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
206206
Firmata.sendString("I2C: Too many bytes received");
207207
} else if (numBytes > Wire.available()) {
208208
Firmata.sendString("I2C: Too few bytes received");
209+
numBytes = Wire.available();
209210
}
210211

211212
i2cRxData[0] = address;

examples/StandardFirmataBLE/StandardFirmataBLE.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
219219
Firmata.sendString("I2C: Too many bytes received");
220220
} else if (numBytes > Wire.available()) {
221221
Firmata.sendString("I2C: Too few bytes received");
222+
numBytes = Wire.available();
222223
}
223224

224225
i2cRxData[0] = address;

examples/StandardFirmataChipKIT/StandardFirmataChipKIT.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
203203
Firmata.sendString("I2C: Too many bytes received");
204204
} else if (numBytes > Wire.available()) {
205205
Firmata.sendString("I2C: Too few bytes received");
206+
numBytes = Wire.available();
206207
}
207208

208209
i2cRxData[0] = address;

examples/StandardFirmataEthernet/StandardFirmataEthernet.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
285285
Firmata.sendString("I2C: Too many bytes received");
286286
} else if (numBytes > Wire.available()) {
287287
Firmata.sendString("I2C: Too few bytes received");
288+
numBytes = Wire.available();
288289
}
289290

290291
i2cRxData[0] = address;

examples/StandardFirmataPlus/StandardFirmataPlus.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
231231
Firmata.sendString("I2C: Too many bytes received");
232232
} else if (numBytes > Wire.available()) {
233233
Firmata.sendString("I2C: Too few bytes received");
234+
numBytes = Wire.available();
234235
}
235236

236237
i2cRxData[0] = address;

examples/StandardFirmataWiFi/StandardFirmataWiFi.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ void readAndReportData(byte address, int theRegister, byte numBytes, byte stopTX
290290
Firmata.sendString("I2C: Too many bytes received");
291291
} else if (numBytes > Wire.available()) {
292292
Firmata.sendString("I2C: Too few bytes received");
293+
numBytes = Wire.available();
293294
}
294295

295296
i2cRxData[0] = address;

0 commit comments

Comments
 (0)