Skip to content

Commit 0b937de

Browse files
committed
Fix multi-page write calculation for how many bytes need to be written on each page.
When pageNumber2 is not the next page the calculation returns a value higher than the page size. Instead, use pageNumber1 end and substract the number of bytes already written to that page.
1 parent 271b3c6 commit 0b937de

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/SparkFun_External_EEPROM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite,
209209
uint16_t pageNumber1 = (eepromLocation + recorded) / settings.pageSize_bytes;
210210
uint16_t pageNumber2 = (eepromLocation + recorded + amtToWrite - 1) / settings.pageSize_bytes;
211211
if (pageNumber2 > pageNumber1)
212-
amtToWrite = (pageNumber2 * settings.pageSize_bytes) - (eepromLocation + recorded); //Limit the read amt to go right up to edge of page barrier
212+
amtToWrite = ((pageNumber1+1) * settings.pageSize_bytes) - (eepromLocation + recorded); //Limit the write amt to go right up to edge of page barrier
213213
}
214214

215215
uint8_t i2cAddress = settings.deviceAddress;

0 commit comments

Comments
 (0)