Skip to content

Commit 48f196f

Browse files
authored
Merge pull request #11 from quarcko/master
FIX: Library does not work with small (2-16Kbits) eeprom devices
2 parents 4c6974f + f6283cf commit 48f196f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/SparkFun_External_EEPROM.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ void ExternalEEPROM::read(uint32_t eepromLocation, uint8_t *buff, uint16_t buffe
161161
delayMicroseconds(100); //This shortens the amount of time waiting between writes but hammers the I2C bus
162162

163163
settings.i2cPort->beginTransmission(i2cAddress);
164-
settings.i2cPort->write((uint8_t)((eepromLocation + received) >> 8)); // MSB
164+
if(getMemorySize() > 2048)
165+
settings.i2cPort->write((uint8_t)((eepromLocation + received) >> 8)); // MSB
165166
settings.i2cPort->write((uint8_t)((eepromLocation + received) & 0xFF)); // LSB
166167
settings.i2cPort->endTransmission();
167168

@@ -225,7 +226,8 @@ void ExternalEEPROM::write(uint32_t eepromLocation, const uint8_t *dataToWrite,
225226
delayMicroseconds(100); //This shortens the amount of time waiting between writes but hammers the I2C bus
226227

227228
settings.i2cPort->beginTransmission(i2cAddress);
228-
settings.i2cPort->write((uint8_t)((eepromLocation + recorded) >> 8)); // MSB
229+
if(getMemorySize() > 2048)
230+
settings.i2cPort->write((uint8_t)((eepromLocation + recorded) >> 8)); // MSB
229231
settings.i2cPort->write((uint8_t)((eepromLocation + recorded) & 0xFF)); // LSB
230232
for (uint8_t x = 0; x < amtToWrite; x++)
231233
settings.i2cPort->write(dataToWrite[recorded + x]);

0 commit comments

Comments
 (0)