mirror of
https://github.com/RobTillaart/I2C_EEPROM.git
synced 2026-10-26 22:10:15 +00:00
1 parent
c0a952e406
commit
5e12716b9c
8 files changed
+129
-38
No files matched your search
+35
-26
@@ -1,36 +1,37 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.3.0
|
||||
// VERSION: 1.3.1
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.00 - 2011-01-21 initial version
|
||||
// 0.1.01 - 2011-02-07 added setBlock function
|
||||
// 0.2.00 - 2011-02-11 fixed 64 bit boundary bug
|
||||
// 0.2.01 - 2011-08-13 _readBlock made more robust + return value
|
||||
// 1.0.00 - 2013-06-09 support for Arduino 1.0.x
|
||||
// 1.0.01 - 2013-11-01 fixed writeBlock bug, refactor
|
||||
// 1.0.02 - 2013-11-03 optimize internal buffers, refactor
|
||||
// 1.0.03 - 2013-11-03 refactor 5 millis() write-latency
|
||||
// 1.0.04 - 2013-11-03 fix bug in readBlock, moved waitEEReady()
|
||||
// -> more efficient.
|
||||
// 1.0.05 - 2013-11-06 improved waitEEReady(),
|
||||
// added determineSize()
|
||||
// 1.1.00 - 2013-11-13 added begin() function (Note breaking interface)
|
||||
// use faster block Wire.write()
|
||||
// int casting removed
|
||||
// 1.2.00 - 2014-05-21 Added support for Arduino DUE ( thanks to Tyler F.)
|
||||
// 1.2.01 - 2014-05-21 Refactoring
|
||||
// 1.2.02 - 2015-03-06 stricter interface
|
||||
// 1.2.03 - 2015-05-15 bugfix in _pageBlock & example (thanks ifreislich )
|
||||
// 1.2.4 2017-04-19 remove timeout - issue #63
|
||||
// 1.2.5 2017-04-20 refactor the removed timeout (Thanks to Koepel)
|
||||
// 1.2.6 2019-02-01 fix issue #121
|
||||
// 1.2.7 2019-09-03 fix issue #113 and #128
|
||||
// 1.3.0 2020-06-19 refactor; removed pre 1.0 support; added ESP32 support.
|
||||
//
|
||||
// 0.1.00 - 2011-01-21 initial version
|
||||
// 0.1.01 - 2011-02-07 added setBlock function
|
||||
// 0.2.00 - 2011-02-11 fixed 64 bit boundary bug
|
||||
// 0.2.01 - 2011-08-13 _readBlock made more robust + return value
|
||||
// 1.0.00 - 2013-06-09 support for Arduino 1.0.x
|
||||
// 1.0.01 - 2013-11-01 fixed writeBlock bug, refactor
|
||||
// 1.0.02 - 2013-11-03 optimize internal buffers, refactor
|
||||
// 1.0.03 - 2013-11-03 refactor 5 millis() write-latency
|
||||
// 1.0.04 - 2013-11-03 fix bug in readBlock, moved waitEEReady()
|
||||
// -> more efficient.
|
||||
// 1.0.05 - 2013-11-06 improved waitEEReady(),
|
||||
// added determineSize()
|
||||
// 1.1.00 - 2013-11-13 added begin() function (Note breaking interface)
|
||||
// use faster block Wire.write()
|
||||
// int casting removed
|
||||
// 1.2.00 - 2014-05-21 Added support for Arduino DUE ( thanks to Tyler F.)
|
||||
// 1.2.01 - 2014-05-21 Refactoring
|
||||
// 1.2.02 - 2015-03-06 stricter interface
|
||||
// 1.2.03 - 2015-05-15 bugfix in _pageBlock & example (thanks ifreislich )
|
||||
// 1.2.4 2017-04-19 remove timeout - issue #63
|
||||
// 1.2.5 2017-04-20 refactor the removed timeout (Thanks to Koepel)
|
||||
// 1.2.6 2019-02-01 fix issue #121
|
||||
// 1.2.7 2019-09-03 fix issue #113 and #128
|
||||
// 1.3.0 2020-06-19 refactor; removed pre 1.0 support; added ESP32 support.
|
||||
// 1.3.1 2020-12-22 arduino-ci + unit tests + updateByte()
|
||||
|
||||
|
||||
#include <I2C_eeprom.h>
|
||||
|
||||
@@ -124,6 +125,14 @@ uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t* buffer, co
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
int I2C_eeprom::updateByte(const uint16_t memoryAddress, const uint8_t data)
|
||||
{
|
||||
if (data == readByte(memoryAddress)) return 0;
|
||||
return writeByte(memoryAddress, data);
|
||||
}
|
||||
|
||||
|
||||
// returns 64, 32, 16, 8, 4, 2, 1, 0
|
||||
// 0 is smaller than 1K
|
||||
int I2C_eeprom::determineSize()
|
||||
|
||||
+10
-6
@@ -2,17 +2,17 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.3.0
|
||||
// VERSION: 1.3.1
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
|
||||
//
|
||||
// HISTORY: See I2C_eeprom.cpp
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#define I2C_EEPROM_VERSION "1.3.0"
|
||||
#define I2C_EEPROM_VERSION "1.3.1"
|
||||
|
||||
// The DEFAULT page size. This is overriden if you use the second constructor.
|
||||
// I2C_EEPROM_PAGESIZE must be multiple of 2 e.g. 16, 32 or 64
|
||||
@@ -47,17 +47,21 @@ public:
|
||||
void begin();
|
||||
|
||||
// writes a byte to memaddr
|
||||
int writeByte(const uint16_t memoryAddress, const uint8_t value);
|
||||
int writeByte(const uint16_t memoryAddress, const uint8_t value);
|
||||
// writes length bytes from buffer to EEPROM
|
||||
int writeBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length);
|
||||
int writeBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length);
|
||||
// set length bytes in the EEPROM to the same value.
|
||||
int setBlock(const uint16_t memoryAddress, const uint8_t value, const uint16_t length);
|
||||
int setBlock(const uint16_t memoryAddress, const uint8_t value, const uint16_t length);
|
||||
|
||||
// returns the value stored in memaddr
|
||||
uint8_t readByte(const uint16_t memoryAddress);
|
||||
// reads length bytes into buffer
|
||||
uint16_t readBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint16_t length);
|
||||
|
||||
// updates a byte at memory address, writes only if there is a new value.
|
||||
// return 0 if data is same or written OK, error code otherwise.
|
||||
int updateByte(const uint16_t memoryAddress, const uint8_t value);
|
||||
|
||||
int determineSize();
|
||||
|
||||
private:
|
||||
|
||||
@@ -20,14 +20,14 @@ The interface is pretty straightforward
|
||||
- **setBlock(address, value, length)** e.g. use to clear I2C EEPROM
|
||||
- **readByte(address)** - read a single byte from a given address
|
||||
- **readBlock(address, buffer, length)**
|
||||
- **updateByte(address, value)** write a single byte, but only if changed.
|
||||
- **determineSize()**
|
||||
|
||||
|
||||
## Limitation
|
||||
|
||||
The library does not offer multiple EEPROMS as one
|
||||
continuous storage device.
|
||||
|
||||
continuous storage device.
|
||||
|
||||
## Operational
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_update.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: demo I2C_EEPROM library - updateByte
|
||||
//
|
||||
|
||||
#include <Wire.h>
|
||||
#include <I2C_eeprom.h>
|
||||
|
||||
#define MEMORY_SIZE 0x2000 // total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
|
||||
|
||||
I2C_eeprom ee(0x50, MEMORY_SIZE);
|
||||
|
||||
uint32_t start, dur1, dur2;
|
||||
|
||||
void setup()
|
||||
{
|
||||
ee.begin();
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // wait for SERIAL_OUT port to connect. Needed for Leonardo only
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
|
||||
Serial.println("\nTEST: determine size");
|
||||
int size = ee.determineSize();
|
||||
if (size > 0)
|
||||
{
|
||||
Serial.print("SIZE: ");
|
||||
Serial.print(size);
|
||||
Serial.println(" KB");
|
||||
}
|
||||
else if (size == 0)
|
||||
{
|
||||
Serial.println("WARNING: Can't determine eeprom size");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("ERROR: Can't find eeprom\nstopped...");
|
||||
while(1);
|
||||
}
|
||||
|
||||
Serial.println("\nTEST: 100x writebyte()");
|
||||
delay(10);
|
||||
ee.setBlock(0, 0, 100); // clear first 100 bytes
|
||||
start = micros();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ee.writeByte(i, 0);
|
||||
}
|
||||
dur1 = micros() - start;
|
||||
Serial.print("DUR1: ");
|
||||
Serial.println(dur1);
|
||||
delay(10);
|
||||
|
||||
Serial.println("\nTEST: 100x updateByte()");
|
||||
ee.setBlock(0, 0, 100); // clear first 100 bytes
|
||||
start = micros();
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ee.updateByte(i, 0);
|
||||
}
|
||||
dur2 = micros() - start;
|
||||
Serial.print("DUR2: ");
|
||||
Serial.println(dur2);
|
||||
delay(10);
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE
|
||||
@@ -10,5 +10,6 @@ setBlock KEYWORD2
|
||||
readBlock KEYWORD2
|
||||
writeBlock KEYWORD2
|
||||
determineSize KEYWORD2
|
||||
updateByte KEYWORD2
|
||||
|
||||
# Constants (LITERAL1)
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
|
||||
},
|
||||
"version":"1.3.0",
|
||||
"version":"1.3.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
name=I2C_EEPROM
|
||||
version=1.3.0
|
||||
version=1.3.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for I2C EEPROMS.
|
||||
@@ -8,4 +8,4 @@ category=Data Storage
|
||||
url=https://github.com/RobTillaart/I2C_EEPROM.git
|
||||
architectures=*
|
||||
includes=I2C_eeprom.h
|
||||
depends=
|
||||
depends=
|
||||
@@ -56,7 +56,7 @@ unittest(test_new_operator)
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
I2C_eeprom EE(48);
|
||||
I2C_eeprom EE(0x50);
|
||||
EE.begin();
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user