Skip to content

Commit

Permalink
Fixing a problem where the Wire library limits the maximum number of …
Browse files Browse the repository at this point in the history
…bytes sent in one block.

* The write library limits the number of written bytes in one block. This fix checks if this limit is reached and splits the transfer into multiple blocks with the maximum size.
  • Loading branch information
t-paul authored and LuckyResistor committed Apr 17, 2017
1 parent a2c4592 commit 729756c
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions LRAS1130.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,31 @@ void AS1130::writeToMemory(uint8_t registerSelection, uint8_t address, const uin
void AS1130::fillMemory(uint8_t registerSelection, uint8_t address, uint8_t value, uint8_t size)
{
writeToChip(cRegisterSelectionAddress, registerSelection);
Wire.beginTransmission(_chipAddress);
Wire.write(address);
for (uint8_t i = 0; i < size; ++i) {
Wire.write(value);
}
Wire.endTransmission();
while (size > 0) {
Wire.beginTransmission(_chipAddress);
if (Wire.write(address) == 0) {
// With failed address write, there is not much chance to do
// anything useful, so this just finishes the transmission
// and returns, leaving the error state set in the Wire
// library.
Wire.endTransmission();
return;
}

// Send as much bytes as possible in one loop, by default the
// Arduino Wire library has a 32 byte buffer, so we can send
// a maximum of 31 data bytes at once (in addition to the
// address byte).
while (size > 0) {
if (Wire.write(value) == 0) {
Wire.clearWriteError();
break;
}
size--;
address++;
}
Wire.endTransmission();
}
}


Expand Down

0 comments on commit 729756c

Please sign in to comment.