1.8.4 I2C_EEPROM

This commit is contained in:
Rob Tillaart 2024-04-21 11:00:27 +02:00
parent cbbffdb59f
commit 4bfffcf63f
18 changed files with 153 additions and 119 deletions

View File

@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## [1.8.4] - 2024-04-20
- Fix #70, increase length internal buffer.
- add compile time flag **EN_AUTO_WRITE_PROTECT** (thanks to microfoundry)
- improve readability: cnt => count addr => address
- add URL to examples
- minor edits.
## [1.8.3] - 2024-03-28 ## [1.8.3] - 2024-03-28
- Fix #64, compiler warning. - Fix #64, compiler warning.
- add **verifyBlock(memoryAddress, buffer, length)** - add **verifyBlock(memoryAddress, buffer, length)**
@ -15,7 +23,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- update examples - update examples
- update readme.md - update readme.md
## [1.8.2] - 2024-01-02 ## [1.8.2] - 2024-01-02
- updated **uint32_t determineSizeNoWrite()**, kudos to roelandkluit - updated **uint32_t determineSizeNoWrite()**, kudos to roelandkluit
- minor edits - minor edits

View File

@ -1,9 +1,9 @@
// //
// FILE: I2C_eeprom.cpp // FILE: I2C_eeprom.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 1.8.3 // VERSION: 1.8.4
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git // URL: https://github.com/RobTillaart/I2C_EEPROM
#include "I2C_eeprom.h" #include "I2C_eeprom.h"
@ -60,6 +60,7 @@ bool I2C_eeprom::begin(int8_t writeProtectPin)
_writeProtectPin = writeProtectPin; _writeProtectPin = writeProtectPin;
if (_writeProtectPin >= 0) if (_writeProtectPin >= 0)
{ {
_autoWriteProtect = EN_AUTO_WRITE_PROTECT;
pinMode(_writeProtectPin, OUTPUT); pinMode(_writeProtectPin, OUTPUT);
preventWrite(); preventWrite();
} }
@ -131,38 +132,38 @@ uint8_t I2C_eeprom::readByte(const uint16_t memoryAddress)
// returns bytes read. // returns bytes read.
uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length) uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length)
{ {
uint16_t addr = memoryAddress; uint16_t address = memoryAddress;
uint16_t len = length; uint16_t len = length;
uint16_t rv = 0; uint16_t bytes = 0;
while (len > 0) while (len > 0)
{ {
uint8_t cnt = I2C_BUFFERSIZE; uint8_t count = I2C_BUFFERSIZE;
if (cnt > len) cnt = len; if (count > len) count = len;
rv += _ReadBlock(addr, buffer, cnt); bytes += _ReadBlock(address, buffer, count);
addr += cnt; address += count;
buffer += cnt; buffer += count;
len -= cnt; len -= count;
} }
return rv; return bytes;
} }
// returns true or false. // returns true or false.
bool I2C_eeprom::verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) bool I2C_eeprom::verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{ {
uint16_t addr = memoryAddress; uint16_t address = memoryAddress;
uint16_t len = length; uint16_t len = length;
while (len > 0) while (len > 0)
{ {
uint8_t cnt = I2C_BUFFERSIZE; uint8_t count = I2C_BUFFERSIZE;
if (cnt > len) cnt = len; if (count > len) count = len;
if (_verifyBlock(addr, buffer, cnt) == false) if (_verifyBlock(address, buffer, count) == false)
{ {
return false; return false;
} }
addr += cnt; address += count;
buffer += cnt; buffer += count;
len -= cnt; len -= count;
} }
return true; return true;
} }
@ -184,25 +185,25 @@ int I2C_eeprom::updateByte(const uint16_t memoryAddress, const uint8_t data)
// returns bytes written. // returns bytes written.
uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{ {
uint16_t addr = memoryAddress; uint16_t address = memoryAddress;
uint16_t len = length; uint16_t len = length;
uint16_t rv = 0; uint16_t bytes = 0;
while (len > 0) while (len > 0)
{ {
uint8_t buf[I2C_BUFFERSIZE]; uint8_t buf[I2C_BUFFERSIZE];
uint8_t cnt = I2C_BUFFERSIZE; uint8_t count = I2C_BUFFERSIZE;
if (cnt > len) cnt = len; if (count > len) count = len;
rv += _ReadBlock(addr, buf, cnt); bytes += _ReadBlock(address, buf, count);
if (memcmp(buffer, buf, cnt) != 0) if (memcmp(buffer, buf, count) != 0)
{ {
_pageBlock(addr, buffer, cnt, true); _pageBlock(address, buffer, count, true);
} }
addr += cnt; address += count;
buffer += cnt; buffer += count;
len -= cnt; len -= count;
} }
return rv; return bytes;
} }
@ -305,12 +306,12 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
uint8_t buf = readByte(size); uint8_t buf = readByte(size);
// test folding // test folding
uint8_t cnt = 0; uint8_t count = 0;
writeByte(size, pat55); writeByte(size, pat55);
if (readByte(0) == pat55) cnt++; if (readByte(0) == pat55) count++;
writeByte(size, patAA); writeByte(size, patAA);
if (readByte(0) == patAA) cnt++; if (readByte(0) == patAA) count++;
folded = (cnt == 2); folded = (count == 2);
if (debug) if (debug)
{ {
SPRNH(size, HEX); SPRNH(size, HEX);
@ -327,6 +328,7 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
return 0; return 0;
} }
// new 1.8.1 #61 // new 1.8.1 #61
// updated 1.8.2 #63 // updated 1.8.2 #63
// //
@ -344,7 +346,7 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
if (!isConnected()) return 0; if (!isConnected()) return 0;
bool addressSize = _isAddressSizeTwoWords; bool addressSize = _isAddressSizeTwoWords;
_isAddressSizeTwoWords = true; //Otherwise reading large EEPROMS fails _isAddressSizeTwoWords = true; // Otherwise reading large EEPROMS fails
bool isModifiedFirstSector = false; bool isModifiedFirstSector = false;
bool dataIsDifferent = false; bool dataIsDifferent = false;
@ -356,8 +358,8 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
{ {
if (dataIsDifferent || pos == 0) if (dataIsDifferent || pos == 0)
{ {
//ignore futher comparison if dataFirstBytes is not the same in buffer // ignore further comparison if dataFirstBytes is not the same in buffer
//Ignore first byte // Ignore first byte
} }
else if (dataFirstBytes[pos - 1] != dataFirstBytes[pos]) else if (dataFirstBytes[pos - 1] != dataFirstBytes[pos])
{ {
@ -366,7 +368,7 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
if (dataFirstBytes[pos] != 0xFF && dataFirstBytes[pos] != 0x00) if (dataFirstBytes[pos] != 0xFF && dataFirstBytes[pos] != 0x00)
{ {
//Default dataFirstBytes value is 0xFF or 0x00 // Default dataFirstBytes value is 0xFF or 0x00
isModifiedFirstSector = true; isModifiedFirstSector = true;
} }
@ -376,31 +378,34 @@ uint32_t I2C_eeprom::determineSizeNoWrite()
if (!isModifiedFirstSector) if (!isModifiedFirstSector)
{ {
//Cannot determine diff, at least one of the first bytes within 0 - len [BUFSIZE] needs to be changed. // Cannot determine diff, at least one of the first bytes within 0 - len [BUFSIZE] needs to be changed
//to something other than 0x00 and 0xFF // to something other than 0x00 and 0xFF
_isAddressSizeTwoWords = addressSize; _isAddressSizeTwoWords = addressSize;
return 1; return 1;
} }
if (!dataIsDifferent) if (!dataIsDifferent)
{ {
//Data in first bytes within 0 - len [BUFSIZE] are all the same. // Data in first bytes within 0 - len [BUFSIZE] are all the same.
_isAddressSizeTwoWords = addressSize; _isAddressSizeTwoWords = addressSize;
return 2; return 2;
} }
//Read from larges to smallest size // Read from largest to smallest size
for (uint32_t size = 32768; size >= 64; size /= 2) for (uint32_t size = 32768; size >= 64; size /= 2)
{ {
_isAddressSizeTwoWords = (size >= I2C_DEVICESIZE_24LC16); // == 2048 _isAddressSizeTwoWords = (size >= I2C_DEVICESIZE_24LC16); // == 2048
// Try to read last byte of the block, should return length of 0 when fails for single byte devices // Try to read last byte of the block, should return length of 0 when fails for single byte devices
// Will return the same dataFirstBytes as initialy read on other devices as the datapointer could not be moved to the requested position // Will return the same dataFirstBytes as initially read on other devices
// as the data pointer could not be moved to the requested position
delay(2); delay(2);
uint16_t bSize = readBlock(size, dataMatch, BUFSIZE); uint16_t bSize = readBlock(size, dataMatch, BUFSIZE);
if (bSize == BUFSIZE && memcmp(dataFirstBytes, dataMatch, BUFSIZE) != 0) if (bSize == BUFSIZE && memcmp(dataFirstBytes, dataMatch, BUFSIZE) != 0)
{ {
//Read is perfomed just over size (size + BUFSIZE), this will only work for devices with mem > size; therefore return size * 2 // Read is performed just over size (size + BUFSIZE),
// this will only work for devices with mem > size;
// therefore return size * 2
_isAddressSizeTwoWords = addressSize; _isAddressSizeTwoWords = addressSize;
return size * 2; return size * 2;
} }
@ -542,22 +547,22 @@ bool I2C_eeprom::getAutoWriteProtect()
// returns 0 = OK otherwise error // returns 0 = OK otherwise error
int I2C_eeprom::_pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer) int I2C_eeprom::_pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer)
{ {
uint16_t addr = memoryAddress; uint16_t address = memoryAddress;
uint16_t len = length; uint16_t len = length;
while (len > 0) while (len > 0)
{ {
uint8_t bytesUntilPageBoundary = this->_pageSize - addr % this->_pageSize; uint8_t bytesUntilPageBoundary = this->_pageSize - address % this->_pageSize;
uint8_t cnt = I2C_BUFFERSIZE; uint8_t count = I2C_BUFFERSIZE;
if (cnt > len) cnt = len; if (count > len) count = len;
if (cnt > bytesUntilPageBoundary) cnt = bytesUntilPageBoundary; if (count > bytesUntilPageBoundary) count = bytesUntilPageBoundary;
int rv = _WriteBlock(addr, buffer, cnt); int rv = _WriteBlock(address, buffer, count);
if (rv != 0) return rv; if (rv != 0) return rv;
addr += cnt; address += count;
if (incrBuffer) buffer += cnt; if (incrBuffer) buffer += count;
len -= cnt; len -= count;
} }
return 0; return 0;
} }
@ -574,8 +579,8 @@ void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress)
} }
else else
{ {
uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07); uint8_t address = _deviceAddress | ((memoryAddress >> 8) & 0x07);
_wire->beginTransmission(addr); _wire->beginTransmission(address);
} }
// Address Low Byte // Address Low Byte
@ -586,7 +591,7 @@ void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress)
// pre: length <= this->_pageSize && length <= I2C_BUFFERSIZE; // pre: length <= this->_pageSize && length <= I2C_BUFFERSIZE;
// returns 0 = OK otherwise error // returns 0 = OK otherwise error
int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length) int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{ {
_waitEEReady(); _waitEEReady();
if (_autoWriteProtect) if (_autoWriteProtect)
@ -624,7 +629,7 @@ int I2C_eeprom::_WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer
// pre: buffer is large enough to hold length bytes // pre: buffer is large enough to hold length bytes
// returns bytes read // returns bytes read
uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint8_t length) uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length)
{ {
_waitEEReady(); _waitEEReady();
@ -650,14 +655,14 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
} }
else else
{ {
uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07); uint8_t address = _deviceAddress | ((memoryAddress >> 8) & 0x07);
readBytes = _wire->requestFrom(addr, length); readBytes = _wire->requestFrom(address, length);
} }
yield(); // For OS scheduling yield(); // For OS scheduling
uint8_t cnt = 0; uint8_t count = 0;
while (cnt < readBytes) while (count < readBytes)
{ {
buffer[cnt++] = _wire->read(); buffer[count++] = _wire->read();
} }
return readBytes; return readBytes;
} }
@ -665,7 +670,7 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, c
// compares content of EEPROM with buffer. // compares content of EEPROM with buffer.
// returns true if equal. // returns true if equal.
bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length) bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length)
{ {
_waitEEReady(); _waitEEReady();
@ -691,14 +696,14 @@ bool I2C_eeprom::_verifyBlock(const uint16_t memoryAddress, const uint8_t * buff
} }
else else
{ {
uint8_t addr = _deviceAddress | ((memoryAddress >> 8) & 0x07); uint8_t address = _deviceAddress | ((memoryAddress >> 8) & 0x07);
readBytes = _wire->requestFrom(addr, length); readBytes = _wire->requestFrom(address, length);
} }
yield(); // For OS scheduling yield(); // For OS scheduling
uint8_t cnt = 0; uint8_t count = 0;
while (cnt < readBytes) while (count < readBytes)
{ {
if (buffer[cnt++] != _wire->read()) if (buffer[count++] != _wire->read())
{ {
return false; return false;
} }

View File

@ -2,16 +2,16 @@
// //
// FILE: I2C_eeprom.h // FILE: I2C_eeprom.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 1.8.3 // VERSION: 1.8.4
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
// URL: https://github.com/RobTillaart/I2C_EEPROM.git // URL: https://github.com/RobTillaart/I2C_EEPROM
#include "Arduino.h" #include "Arduino.h"
#include "Wire.h" #include "Wire.h"
#define I2C_EEPROM_VERSION (F("1.8.3")) #define I2C_EEPROM_VERSION (F("1.8.4"))
#define I2C_DEVICESIZE_24LC512 65536 #define I2C_DEVICESIZE_24LC512 65536
#define I2C_DEVICESIZE_24LC256 32768 #define I2C_DEVICESIZE_24LC256 32768
@ -33,6 +33,15 @@
#define I2C_WRITEDELAY 5000 #define I2C_WRITEDELAY 5000
#endif #endif
// set the flag EN_AUTO_WRITE_PROTECT to 1 to enable the Write Control at compile time
// used if the write_protect pin is explicitly set in the begin() function.
// the flag can be set as command line option.
#ifndef EN_AUTO_WRITE_PROTECT
#define EN_AUTO_WRITE_PROTECT 0
#endif
#ifndef UNIT_TEST_FRIEND #ifndef UNIT_TEST_FRIEND
#define UNIT_TEST_FRIEND #define UNIT_TEST_FRIEND
#endif #endif
@ -162,11 +171,11 @@ private:
// TODO incrBuffer is an implementation name, not a functional name. // TODO incrBuffer is an implementation name, not a functional name.
int _pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer); int _pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer);
// returns I2C status, 0 = OK // returns I2C status, 0 = OK
int _WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length); int _WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length);
// returns bytes read. // returns bytes read.
uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint8_t length); uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length);
// compare bytes in EEPROM. // compare bytes in EEPROM.
bool _verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length); bool _verifyBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length);
// to optimize the write latency of the EEPROM // to optimize the write latency of the EEPROM
void _waitEEReady(); void _waitEEReady();
@ -176,7 +185,7 @@ private:
bool _debug = false; bool _debug = false;
int8_t _writeProtectPin = -1; int8_t _writeProtectPin = -1;
bool _autoWriteProtect = false; bool _autoWriteProtect = EN_AUTO_WRITE_PROTECT;
UNIT_TEST_FRIEND; UNIT_TEST_FRIEND;
}; };

View File

@ -3,20 +3,20 @@
// AUTHOR: Tomas Hübner // AUTHOR: Tomas Hübner
// VERSION: 1.0.0 // VERSION: 1.0.0
// PURPOSE: Simple example of how to use cyclic storage. // PURPOSE: Simple example of how to use cyclic storage.
// // URL: https://github.com/RobTillaart/I2C_EEPROM
#include <I2C_eeprom.h> #include <I2C_eeprom.h>
#include <I2C_eeprom_cyclic_store.h> #include <I2C_eeprom_cyclic_store.h>
#define MEMORY_SIZE 0x2000 // Total capacity of the EEPROM #define MEMORY_SIZE 8192 // Total capacity of the EEPROM (8K == 8192 == 0x2000)
#define PAGE_SIZE 64 // Size of write page of device, use datasheet to find! #define PAGE_SIZE 64 // Size of write page of device, use datasheet to find!
struct SampleData { struct SampleData {
public: public:
uint32_t counter; uint32_t counter;
// Must use fixed length string, avoid using the String class. // Must use fixed length string, avoid using the String class.
char message[32]; char message[32];
}; };

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_determineSize.ino // FILE: I2C_eeprom_determineSize.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: test determinSize() function // PURPOSE: test determinSize() function
// URL: https://github.com/RobTillaart/I2C_EEPROM
#include "Wire.h" #include "Wire.h"
@ -34,7 +35,7 @@ void setup()
delay(10); delay(10);
start = micros(); start = micros();
uint32_t size = ee.determineSize(false); // debug param uint32_t size = ee.determineSize(false); // debug parameter
diff = micros() - start; diff = micros() - start;
Serial.print("TIME: "); Serial.print("TIME: ");
Serial.print(diff); Serial.print(diff);
@ -70,5 +71,5 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_determineSizeNoWrite.ino // FILE: I2C_eeprom_determineSizeNoWrite.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: test determineSizeNoWrite() function // PURPOSE: test determineSizeNoWrite() function
// URL: https://github.com/RobTillaart/I2C_EEPROM
#include "Wire.h" #include "Wire.h"

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_format.ino // FILE: I2C_eeprom_format.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo format EEPROM // PURPOSE: demo format EEPROM
// URL: https://github.com/RobTillaart/I2C_EEPROM
#include "Wire.h" #include "Wire.h"
@ -32,7 +33,7 @@ void setup()
Serial.println(); Serial.println();
uint32_t size = ee.determineSize(false); // debug param uint32_t size = ee.determineSize(false); // debug parameter
if (size == 0) if (size == 0)
{ {
Serial.println("SIZE: could not determine size"); Serial.println("SIZE: could not determine size");
@ -85,4 +86,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,9 +2,10 @@
// FILE: I2C_eeprom_struct.ino // FILE: I2C_eeprom_struct.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library store /retrieve struct // PURPOSE: demo I2C_EEPROM library store /retrieve struct
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM
// as this test writes a lot it might wear out EEPROMs eventually. // as this test writes a lot it might wear out EEPROMs eventually.
// //
@ -44,15 +45,15 @@ void setup()
Serial.print("size: \t"); Serial.print("size: \t");
Serial.println(sizeof(measurement)); Serial.println(sizeof(measurement));
// clear EEPROM part // clear EEPROM part
ee.setBlock(0, 0, sizeof(measurement)); ee.setBlock(0, 0, sizeof(measurement));
// make measurement here // make measurement here
measurement.temperature = 22.5; measurement.temperature = 22.5;
measurement.humidity = 53.1; measurement.humidity = 53.1;
measurement.pressure = 1000.9; measurement.pressure = 1000.9;
// store it in EEPROM // store it in EEPROM
start = micros(); start = micros();
ee.writeBlock(0, (uint8_t *) &measurement, sizeof(measurement)); ee.writeBlock(0, (uint8_t *) &measurement, sizeof(measurement));
duration = micros() - start; duration = micros() - start;
@ -60,12 +61,12 @@ void setup()
Serial.println(duration); Serial.println(duration);
delay(10); delay(10);
// clear measurement struct // clear measurement struct
measurement.temperature = 0; measurement.temperature = 0;
measurement.humidity = 0; measurement.humidity = 0;
measurement.pressure = 0; measurement.pressure = 0;
// retrieve old measurement // retrieve old measurement
start = micros(); start = micros();
ee.readBlock(0, (uint8_t *) &measurement, sizeof(measurement)); ee.readBlock(0, (uint8_t *) &measurement, sizeof(measurement));
duration = micros() - start; duration = micros() - start;
@ -89,5 +90,5 @@ void loop()
} }
// -- END OF FILE // -- END OF FILE

View File

@ -2,18 +2,19 @@
// FILE: I2C_eeprom_test.ino // FILE: I2C_eeprom_test.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: show/test I2C_EEPROM library // PURPOSE: show/test I2C_EEPROM library
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM
// might need adaptions for other EEPROMS (page size etc) // might need adaptions for other EEPROMS (page size etc)
#include "Wire.h" #include "Wire.h"
#include "I2C_eeprom.h" #include "I2C_eeprom.h"
// UNO // UNO
#define SERIAL_OUT Serial #define SERIAL_OUT Serial
// Due // Due
// #define SERIAL_OUT SerialUSB // #define SERIAL_OUT SerialUSB
@ -247,5 +248,5 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_test_performance.ino // FILE: I2C_eeprom_test_performance.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: test I2C_EEPROM library // PURPOSE: test I2C_EEPROM library
// URL: https://github.com/RobTillaart/I2C_EEPROM
#include "Wire.h" #include "Wire.h"
@ -94,7 +95,7 @@ void test()
Serial.println(totals); Serial.println(totals);
totals = 0; totals = 0;
// same tests but now with a 5 millisec delay in between. // same tests but now with a 5 milliseconds delay in between.
delay(5); delay(5);
Serial.print("\nTEST: timing writeByte()\t"); Serial.print("\nTEST: timing writeByte()\t");
@ -180,5 +181,5 @@ void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,8 +2,9 @@
// FILE: I2C_eeprom_update.ino // FILE: I2C_eeprom_update.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library - updateByte // PURPOSE: demo I2C_EEPROM library - updateByte
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM
#include "Wire.h" #include "Wire.h"
@ -52,7 +53,7 @@ void setup()
Serial.println("\nTEST: 100x writebyte()"); Serial.println("\nTEST: 100x writebyte()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@ -64,7 +65,7 @@ void setup()
delay(10); delay(10);
Serial.println("\nTEST: 100x updateByte()"); Serial.println("\nTEST: 100x updateByte()");
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@ -84,5 +85,5 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_updateBlock.ino // FILE: I2C_eeprom_updateBlock.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library - performance gain updateBlock // PURPOSE: demo I2C_EEPROM library - performance gain updateBlock
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM
// as this test writes a lot it might wear out EEPROMs eventually. // as this test writes a lot it might wear out EEPROMs eventually.
@ -58,7 +59,7 @@ void test_1(int n)
Serial.println(n); Serial.println(n);
Serial.print("TEST:\twriteBlock()"); Serial.print("TEST:\twriteBlock()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < n; i++) ee.writeBlock(0, ar, 100); for (int i = 0; i < n; i++) ee.writeBlock(0, ar, 100);
dur1 = micros() - start; dur1 = micros() - start;
@ -77,7 +78,7 @@ void test_1(int n)
Serial.print("TEST:\tupdateBlock()"); Serial.print("TEST:\tupdateBlock()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < n; i++) ee.updateBlock(0, ar, 100); for (int i = 0; i < n; i++) ee.updateBlock(0, ar, 100);
dur1 = micros() - start; dur1 = micros() - start;
@ -92,7 +93,7 @@ void test_2()
{ {
Serial.println("\nTEST: 100x writeBlock()"); Serial.println("\nTEST: 100x writeBlock()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@ -106,7 +107,7 @@ void test_2()
Serial.println("\nTEST: 100x updateBlock()"); Serial.println("\nTEST: 100x updateBlock()");
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
{ {
@ -122,7 +123,7 @@ void test_2()
void dump(uint32_t from, uint32_t to) void dump(uint32_t from, uint32_t to)
{ {
for (uint32_t i = from; i < to; i++) // I2C_DEVICESIZE_24LC512 for (uint32_t i = from; i < to; i++) // I2C_DEVICESIZE_24LC512
{ {
char buffer[24]; char buffer[24];
if (i % 16 == 0) if (i % 16 == 0)
@ -143,5 +144,5 @@ void dump(uint32_t from, uint32_t to)
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_verify.ino // FILE: I2C_eeprom_verify.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library - updateByte // PURPOSE: demo I2C_EEPROM library - updateByte
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM
@ -38,7 +39,7 @@ void setup()
Serial.println("\n"); Serial.println("\n");
Serial.println("\nTEST: NN x writeByte()"); Serial.println("\nTEST: NN x writeByte()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -51,7 +52,7 @@ void setup()
Serial.println("\nTEST: NN x writeByteVerify()"); Serial.println("\nTEST: NN x writeByteVerify()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -96,7 +97,7 @@ void setup()
Serial.println("\nTEST: NN x updateByteVerify() not same data"); Serial.println("\nTEST: NN x updateByteVerify() not same data");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -129,7 +130,7 @@ void setup()
Serial.println("\nTEST: NN x writeBlockVerify()"); Serial.println("\nTEST: NN x writeBlockVerify()");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -176,7 +177,7 @@ void setup()
strcpy(buffer, "98765432109876543210987654321098765432109876543210"); // 50 bytes strcpy(buffer, "98765432109876543210987654321098765432109876543210"); // 50 bytes
Serial.println("\nTEST: NN x updateBlockVerify() not same data"); Serial.println("\nTEST: NN x updateBlockVerify() not same data");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -194,7 +195,7 @@ void setup()
Serial.println("\nTEST: NN x setBlock() same data"); Serial.println("\nTEST: NN x setBlock() same data");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -207,7 +208,7 @@ void setup()
Serial.println("\nTEST: NN x setBlockVerify() same data"); Serial.println("\nTEST: NN x setBlockVerify() same data");
delay(10); delay(10);
ee.setBlock(0, 0, 100); // clear first 100 bytes ee.setBlock(0, 0, 100); // clear first 100 bytes
start = micros(); start = micros();
for (int i = 0; i < NN; i++) for (int i = 0; i < NN; i++)
{ {
@ -245,4 +246,4 @@ void loop()
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -2,6 +2,7 @@
// FILE: I2C_eeprom_verifyBlock.ino // FILE: I2C_eeprom_verifyBlock.ino
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// PURPOSE: demo I2C_EEPROM library // PURPOSE: demo I2C_EEPROM library
// URL: https://github.com/RobTillaart/I2C_EEPROM
// //
// uses a 24LC256 (32KB) EEPROM // uses a 24LC256 (32KB) EEPROM

View File

@ -3,6 +3,7 @@
// AUTHOR: Tyler Freeman // AUTHOR: Tyler Freeman
// VERSION: 0.1.1 // VERSION: 0.1.1
// PURPOSE: show/test I2C_EEPROM library with small EEPROMS // PURPOSE: show/test I2C_EEPROM library with small EEPROMS
// URL: https://github.com/RobTillaart/I2C_EEPROM
// HISTORY // HISTORY
// 0.1.0 2014-05-xx initial version // 0.1.0 2014-05-xx initial version
// 0.1.1 2020-07-14 fix #1 compile for ESP; fix author // 0.1.1 2020-07-14 fix #1 compile for ESP; fix author

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/I2C_EEPROM.git" "url": "https://github.com/RobTillaart/I2C_EEPROM.git"
}, },
"version": "1.8.3", "version": "1.8.4",
"license": "MIT", "license": "MIT",
"frameworks": "*", "frameworks": "*",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=I2C_EEPROM name=I2C_EEPROM
version=1.8.3 version=1.8.4
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for I2C EEPROMS sentence=Library for I2C EEPROMS

View File

@ -20,6 +20,8 @@ Arduino Library for external I2C EEPROM - 24LC512, 24LC256, 24LC64/32/16/08/04/0
This library is to access external I2C EEPROM up to 64KB (= 512 Kbit) in size. This library is to access external I2C EEPROM up to 64KB (= 512 Kbit) in size.
MicroChip 24LC512, 24LC256, 24LC64, 24LC32, 24LC16, 24LC08, 24LC04, 24LC02, 24LC01 and equivalents. MicroChip 24LC512, 24LC256, 24LC64, 24LC32, 24LC16, 24LC08, 24LC04, 24LC02, 24LC01 and equivalents.
Also confirmed working M24512-W, M24512-R, M24512-DF (See #68).
Not supported is the identification page functions.
The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md) The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_store.md)