Skip to content

Commit f6283cf

Browse files
authored
FIX: Library does not work with small (2-16Kbits) eeprom devices
For memory chips smaller than 16kbits you need to send only 1 packet (8bits) of adress via I2C. This fix checkes for defined memory size and based on this either sends 16bit adress or 8bit address.
1 parent 4c6974f commit f6283cf

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)