diff --git a/I2C_eeprom.cpp b/I2C_eeprom.cpp index dba0cac..7850e1f 100644 --- a/I2C_eeprom.cpp +++ b/I2C_eeprom.cpp @@ -1,7 +1,7 @@ // // FILE: I2C_eeprom.cpp // AUTHOR: Rob Tillaart -// VERSION: 1.6.0 +// VERSION: 1.6.1 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git // @@ -42,9 +42,11 @@ // 1.5.1 2021-10-14 function to add extra for write cycle (experimental) // 1.5.2 2021-12-19 update library.json, license, minor edits // 1.6.0 2022-06-02 add verify functions. +// 1.6.1 2022-06-11 update documentation, minor edits +// minor improvements / bug fixes -#include +#include "I2C_eeprom.h" // Not used directly #define I2C_PAGESIZE_24LC512 128 @@ -68,13 +70,17 @@ #endif -I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, TwoWire *wire) +//////////////////////////////////////////////////////////////////// +// +// PUBLIC FUNCTIONS +// +I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, TwoWire * wire) { I2C_eeprom(deviceAddress, I2C_PAGESIZE_24LC256, wire); } -I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire *wire) +I2C_eeprom::I2C_eeprom(const uint8_t deviceAddress, const uint32_t deviceSize, TwoWire * wire) { _deviceAddress = deviceAddress; _deviceSize = deviceSize; @@ -117,10 +123,13 @@ bool I2C_eeprom::isConnected() return (_wire->endTransmission() == 0); } + ///////////////////////////////////////////////////////////// // // WRITE SECTION // + +// returns I2C status, 0 = OK int I2C_eeprom::writeByte(const uint16_t memoryAddress, const uint8_t data) { int rv = _WriteBlock(memoryAddress, &data, 1); @@ -128,6 +137,7 @@ int I2C_eeprom::writeByte(const uint16_t memoryAddress, const uint8_t data) } +// returns I2C status, 0 = OK int I2C_eeprom::setBlock(const uint16_t memoryAddress, const uint8_t data, const uint16_t length) { uint8_t buffer[I2C_BUFFERSIZE]; @@ -140,7 +150,8 @@ int I2C_eeprom::setBlock(const uint16_t memoryAddress, const uint8_t data, const } -int I2C_eeprom::writeBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length) +// returns I2C status, 0 = OK +int I2C_eeprom::writeBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) { int rv = _pageBlock(memoryAddress, buffer, length, true); return rv; @@ -151,6 +162,8 @@ int I2C_eeprom::writeBlock(const uint16_t memoryAddress, const uint8_t* buffer, // // READ SECTION // + +// returns the value stored in memoryAddress uint8_t I2C_eeprom::readByte(const uint16_t memoryAddress) { uint8_t rdata; @@ -159,7 +172,8 @@ uint8_t I2C_eeprom::readByte(const uint16_t memoryAddress) } -uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint16_t length) +// returns bytes read. +uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length) { uint16_t addr = memoryAddress; uint16_t len = length; @@ -182,6 +196,7 @@ uint16_t I2C_eeprom::readBlock(const uint16_t memoryAddress, uint8_t* buffer, co // // UPDATE SECTION // + // returns 0 == OK int I2C_eeprom::updateByte(const uint16_t memoryAddress, const uint8_t data) { @@ -190,8 +205,8 @@ int I2C_eeprom::updateByte(const uint16_t memoryAddress, const uint8_t data) } -// returns bytes updated -int I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length) +// returns bytes written. +uint16_t I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) { uint16_t addr = memoryAddress; uint16_t len = length; @@ -220,6 +235,8 @@ int I2C_eeprom::updateBlock(const uint16_t memoryAddress, const uint8_t* buffer, // // VERIFY SECTION // + +// return false if write or verify failed. bool I2C_eeprom::writeByteVerify(const uint16_t memoryAddress, const uint8_t value) { if (writeByte(memoryAddress, value) != 0 ) return false; @@ -228,7 +245,8 @@ bool I2C_eeprom::writeByteVerify(const uint16_t memoryAddress, const uint8_t val } -bool I2C_eeprom::writeBlockVerify(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length) +// return false if write or verify failed. +bool I2C_eeprom::writeBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) { if (writeBlock(memoryAddress, buffer, length) != 0) return false; uint8_t data[length]; @@ -237,12 +255,13 @@ bool I2C_eeprom::writeBlockVerify(const uint16_t memoryAddress, const uint8_t* b } +// return false if write or verify failed. bool I2C_eeprom::setBlockVerify(const uint16_t memoryAddress, const uint8_t value, const uint16_t length) { if (setBlock(memoryAddress, value, length) != 0) return false; uint8_t data[length]; if (readBlock(memoryAddress, data, length) != length) return false; - for (int i = 0; i < length; i++) + for (uint16_t i = 0; i < length; i++) { if (data[i] != value) return false; } @@ -250,6 +269,7 @@ bool I2C_eeprom::setBlockVerify(const uint16_t memoryAddress, const uint8_t valu } +// return false if write or verify failed. bool I2C_eeprom::updateByteVerify(const uint16_t memoryAddress, const uint8_t value) { if (updateByte(memoryAddress, value) != 0 ) return false; @@ -258,7 +278,8 @@ bool I2C_eeprom::updateByteVerify(const uint16_t memoryAddress, const uint8_t va } -bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length) +// return false if write or verify failed. +bool I2C_eeprom::updateBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length) { if (updateBlock(memoryAddress, buffer, length) != length) return false; uint8_t data[length]; @@ -349,7 +370,7 @@ uint8_t I2C_eeprom::getPageSize(uint32_t deviceSize) // _pageBlock aligns buffer to page boundaries for writing. // and to I2C buffer size // 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 len = length; @@ -394,32 +415,53 @@ void I2C_eeprom::_beginTransmission(const uint16_t memoryAddress) // pre: length <= this->_pageSize && length <= I2C_BUFFERSIZE; // 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 uint8_t length) { _waitEEReady(); this->_beginTransmission(memoryAddress); _wire->write(buffer, length); int rv = _wire->endTransmission(); + _lastWrite = micros(); + yield(); - _lastWrite = micros(); +// if (rv != 0) +// { +// if (_debug) +// { +// Serial.print("mem addr w: "); +// Serial.print(memoryAddress, HEX); +// Serial.print("\t"); +// Serial.println(rv); +// } +// return -(abs(rv)); // error +// } return rv; } // pre: buffer is large enough to hold length bytes // 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 uint8_t length) { _waitEEReady(); this->_beginTransmission(memoryAddress); int rv = _wire->endTransmission(); - if (rv != 0) return 0; // error + if (rv != 0) + { +// if (_debug) +// { +// Serial.print("mem addr r: "); +// Serial.print(memoryAddress, HEX); +// Serial.print("\t"); +// Serial.println(rv); +// } + return 0; // error + } // readBytes will always be equal or smaller to length - uint8_t readBytes = 0; if (this->_isAddressSizeTwoWords) { diff --git a/I2C_eeprom.h b/I2C_eeprom.h index 5ce4ce7..744b58a 100644 --- a/I2C_eeprom.h +++ b/I2C_eeprom.h @@ -2,7 +2,7 @@ // // FILE: I2C_eeprom.h // AUTHOR: Rob Tillaart -// VERSION: 1.6.0 +// VERSION: 1.6.1 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git // @@ -13,7 +13,7 @@ #include "Wire.h" -#define I2C_EEPROM_VERSION (F("1.6.0")) +#define I2C_EEPROM_VERSION (F("1.6.1")) #define I2C_DEVICESIZE_24LC512 65536 @@ -56,20 +56,24 @@ public: bool begin(uint8_t sda, uint8_t scl); #endif bool begin(); - bool isConnected(); + // writes a byte to memoryAddress + // returns I2C status, 0 = OK int writeByte(const uint16_t memoryAddress, const uint8_t value); // writes length bytes from buffer to EEPROM + // returns I2C status, 0 = OK int writeBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length); // set length bytes in the EEPROM to the same value. + // returns I2C status, 0 = OK int setBlock(const uint16_t memoryAddress, const uint8_t value, const uint16_t length); // returns the value stored in memoryAddress uint8_t readByte(const uint16_t memoryAddress); // reads length bytes into buffer + // returns bytes read. uint16_t readBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint16_t length); @@ -79,19 +83,21 @@ public: // updates a block in memory, writes only if there is a new value. // only to be used when you expect to write same buffer multiple times. // test your performance gains! - int updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length); + // returns bytes written. + uint16_t updateBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length); + // same functions as above but with verify - // return true if write or verify failed. + // return false if write or verify failed. bool writeByteVerify(const uint16_t memoryAddress, const uint8_t value); bool writeBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length); bool setBlockVerify(const uint16_t memoryAddress, const uint8_t value, const uint16_t length); bool updateByteVerify(const uint16_t memoryAddress, const uint8_t value); bool updateBlockVerify(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length); + // Meta data functions uint32_t determineSize(const bool debug = false); - uint32_t getDeviceSize() { return _deviceSize; }; uint8_t getPageSize() { return _pageSize; }; uint8_t getPageSize(uint32_t deviceSize); @@ -102,9 +108,10 @@ public: void setExtraWriteCycleTime(uint8_t ms) { _extraTWR = ms; }; uint8_t getExtraWriteCycleTime() { return _extraTWR; }; + private: uint8_t _deviceAddress; - uint32_t _lastWrite; // for waitEEReady + uint32_t _lastWrite = 0; // for waitEEReady uint32_t _deviceSize; uint8_t _pageSize; uint8_t _extraTWR = 0; // milliseconds @@ -113,23 +120,22 @@ private: // 24LC01..24LC16 use one-byte addresses + part of device address bool _isAddressSizeTwoWords; - - /** - * Begins wire transmission and selects the given address to write/read. - * - * @param memoryAddress Address to write/read - */ void _beginTransmission(const uint16_t memoryAddress); - int _pageBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint16_t length, const bool incrBuffer); - int _WriteBlock(const uint16_t memoryAddress, const uint8_t* buffer, const uint8_t length); - uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t* buffer, const uint8_t length); + // returns I2C status, 0 = OK + int _pageBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint16_t length, const bool incrBuffer); + // returns I2C status, 0 = OK + int _WriteBlock(const uint16_t memoryAddress, const uint8_t * buffer, const uint8_t length); + // returns bytes read. + uint8_t _ReadBlock(const uint16_t memoryAddress, uint8_t * buffer, const uint8_t length); // to optimize the write latency of the EEPROM void _waitEEReady(); TwoWire * _wire; + bool _debug = false; + UNIT_TEST_FRIEND; }; diff --git a/README.md b/README.md index b7d6dd9..e8c25a6 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_sto ## Interface +The interface is kept quite identical to the I2C_24LC1025 library. +https://github.com/RobTillaart/I2C_24LC1025 + +Most important change is 32 bit memory addresses. + + ### Constructor - **I2C_eeprom(uint8_t deviceAddress, TwoWire \*wire = &Wire)** constructor, optional Wire interface. @@ -33,23 +39,27 @@ The **I2C_eeprom_cyclic_store** interface is documented [here](README_cyclic_sto ### Write functions -- **int writeByte(uint16_t memoryAddress, uint8_t value)** write a single byte to the specified memory address. Returns 0 if OK. -- **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address. Returns 0 if OK. -- **int setBlock(uint16_t memoryAddress, uint8_t value, uint16_t length)** writes the same byte to length places starting at the specified memory address. Returns 0 if OK. +- **int writeByte(uint16_t memoryAddress, uint8_t value)** write a single byte to the specified memory address. +Returns I2C status, 0 = OK. +- **int writeBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address. + Returns I2C status, 0 = OK. +- **int setBlock(uint16_t memoryAddress, uint8_t value, uint16_t length)** writes the same byte to length places starting at the specified memory address. +Returns I2C status, 0 = OK. ### Update functions - **int updateByte(uint16_t memoryAddress, uint8_t value)** write a single byte, but only if changed. Returns 0 if value was same or write succeeded. -- **int updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address, but only if changed. +- **uint16_t updateBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** write a buffer starting at the specified memory address, but only if changed. +Returns bytes written. ### Read functions - **uint8_t readByte(uint16_t memoryAddress)** read a single byte from a given address - **uint16_t readBlock(uint16_t memoryAddress, uint8_t \* buffer, uint16_t length)** read length bytes into buffer starting at specified memory address. -Returns the number of bytes read, which should equal length. +Returns the number of bytes read, which should be length. ### Verify functions @@ -103,7 +113,8 @@ The function cannot detect smaller than 128 bit EEPROMS. The function **updateBlock()** reads the block of data and compares it with the new values to see if it needs rewriting. -As the function reads/writes the data in blocks with a maximum length of **I2C_BUFFERSIZE** (== 30 on AVR limitation). +As the function reads/writes the data in blocks with a maximum length of **I2C_TWIBUFFERSIZE** +(== 30 AVR limitation; 128 for ESP32) It does this comparison in chunks if the length exceeds this number. The result is that an **updateBlock()** call can result e.g. in 4 reads and only 2 writes under the hood. @@ -113,8 +124,6 @@ So you should verify if your sketch can make use of the advantages of **updateBl #### ExtraWriteCycleTime (experimental) -(new since 1.5.1) - To improve support older I2C EEPROMs e.g. IS24C16 two functions were added to increase the waiting time before a read and/or write as some older devices have a larger timeout than 5 milliseconds which is the minimum. @@ -143,7 +152,7 @@ The library does not offer multiple EEPROMS as one continuous storage device. - internals - **\_waitEEReady();** can return bool and could use isConnected() internally. -## Operational +## Operation See examples diff --git a/examples/I2C_eeprom_test/I2C_eeprom_test.ino b/examples/I2C_eeprom_test/I2C_eeprom_test.ino index fb0340c..c08f061 100644 --- a/examples/I2C_eeprom_test/I2C_eeprom_test.ino +++ b/examples/I2C_eeprom_test/I2C_eeprom_test.ino @@ -39,9 +39,12 @@ void setup() SERIAL_OUT.print(I2C_EEPROM_VERSION); SERIAL_OUT.println("\n"); + SERIAL_OUT.print("isConnected:\t"); + SERIAL_OUT.println(ee.isConnected()); + SERIAL_OUT.println("\nTEST: determine size"); start = micros(); - uint32_t size = ee.determineSize(); + uint32_t size = ee.determineSize(true); diff = micros() - start; SERIAL_OUT.print("TIME: "); SERIAL_OUT.println(diff); @@ -63,7 +66,9 @@ void setup() SERIAL_OUT.println("\nTEST: 64 byte page boundary writeBlock"); ee.setBlock(0, 0, 128); dumpEEPROM(0, 128); - char data[] = "11111111111111111111"; + Serial.println("---"); + // char data[] = "11111111111111111111"; + char data[] = "33333333333333333333"; ee.writeBlock(60, (uint8_t*) data, 10); dumpEEPROM(0, 128); diff --git a/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino b/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino index 475e3c6..500d005 100644 --- a/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino +++ b/examples/I2C_eeprom_test_performance/I2C_eeprom_test_performance.ino @@ -38,6 +38,7 @@ void setup() Serial.println(speed); delay(10); test(); + dumpEEPROM(0, 100); } Serial.println("\ndone..."); } diff --git a/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino b/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino new file mode 100644 index 0000000..58ddcc8 --- /dev/null +++ b/examples/I2C_eeprom_verify/I2C_eeprom_verify.ino @@ -0,0 +1,247 @@ +// +// FILE: I2C_eeprom_verify.ino +// AUTHOR: Rob Tillaart +// PURPOSE: demo I2C_EEPROM library - updateByte +// +// uses a 24LC256 (32KB) EEPROM + + +#include "Wire.h" +#include "I2C_eeprom.h" + +#define NN 100 + +I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256); + +uint32_t start, dur1, dur2; + + +void setup() +{ + 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); + + ee.begin(); + if (! ee.isConnected()) + { + Serial.println("ERROR: Can't find eeprom\nstopped..."); + while (1); + } + + Serial.print("\nTestruns NN: "); + Serial.print(NN); + Serial.println("\n"); + Serial.println("\nTEST: NN x writeByte()"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + ee.writeByte(i, 0); + } + dur1 = micros() - start; + Serial.print("DUR1: "); + Serial.println(dur1); + delay(10); + + Serial.println("\nTEST: NN x writeByteVerify()"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.writeByteVerify(i, 0) == false) + { + Serial.print("X"); + } + } + dur1 = micros() - start; + Serial.print("DUR1: "); + Serial.println(dur1); + delay(10); + + ////////////////////////////////////////////////////////////////////// + + Serial.println("\nTEST: NN x updateByte() same data"); + delay(10); + start = micros(); + for (int i = 0; i < NN; i++) + { + ee.updateByte(i, 0); + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + Serial.println("\nTEST: NN x updateByteVerify() same data"); + delay(10); + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.updateByteVerify(i, 0) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + Serial.println("\nTEST: NN x updateByteVerify() not same data"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.updateByteVerify(i, i) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + ////////////////////////////////////////////////////////////////////// + + char buffer[] = "12345678901234567890123456789012345678901234567890"; // 50 bytes + Serial.println("\nTEST: NN x writeBlock()"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + ee.writeBlock(0, (uint8_t *) buffer, 50); + } + dur1 = micros() - start; + Serial.print("DUR1: "); + Serial.println(dur1); + delay(10); + + + Serial.println("\nTEST: NN x writeBlockVerify()"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.writeBlockVerify(0, (uint8_t *) buffer, 50) == false) + { + Serial.print("X"); + } + } + dur1 = micros() - start; + Serial.print("DUR1: "); + Serial.println(dur1); + delay(10); + + ////////////////////////////////////////////////////////////////////// + + Serial.println("\nTEST: NN x updateBlock() same data"); + delay(10); + start = micros(); + for (int i = 0; i < NN; i++) + { + ee.updateBlock(0, (uint8_t *) buffer, 50); + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + + Serial.println("\nTEST: NN x updateBlockVerify() same data"); + delay(10); + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.updateBlockVerify(0, (uint8_t *) buffer, 50) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + strcpy(buffer, "98765432109876543210987654321098765432109876543210"); // 50 bytes + Serial.println("\nTEST: NN x updateBlockVerify() not same data"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.updateBlockVerify(0, (uint8_t *) buffer, 50) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + ////////////////////////////////////////////////////////////////////// + + Serial.println("\nTEST: NN x setBlock() same data"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + ee.setBlock(0, 0, 50); + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + Serial.println("\nTEST: NN x setBlockVerify() same data"); + delay(10); + ee.setBlock(0, 0, 100); // clear first 100 bytes + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.setBlockVerify(0, 0, 50) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + Serial.println("\nTEST: NN x setBlockVerify() not same data"); + delay(10); + start = micros(); + for (int i = 0; i < NN; i++) + { + if (ee.setBlockVerify(0, 1, 50) == false) + { + Serial.print("X"); + } + } + dur2 = micros() - start; + Serial.print("DUR2: "); + Serial.println(dur2); + delay(10); + + Serial.println("done..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/examples/I2C_eeprom_verify/performance_1.6.1.txt b/examples/I2C_eeprom_verify/performance_1.6.1.txt new file mode 100644 index 0000000..fecd605 --- /dev/null +++ b/examples/I2C_eeprom_verify/performance_1.6.1.txt @@ -0,0 +1,43 @@ +I2C_eeprom_verify\I2C_eeprom_verify.ino +VERSION: 1.6.1 + +TEST: 100x writeByte() +DUR1: 367668 + +TEST: 100x writeByteVerify() +DUR1: 442276 + +TEST: 100x updateByte() same data +DUR2: 58472 + +TEST: 100x updateByteVerify() same data +DUR2: 116464 + +TEST: 100x updateByteVerify() not same data +DUR2: 510476 + +TEST: 100x writeBlock() +DUR1: 1216296 + +TEST: 100x writeBlockVerify() +DUR1: 1814332 + +TEST: 100x updateBlock() same data +DUR2: 595220 + +TEST: 100x updateBlockVerify() same data +DUR2: 1190428 + +TEST: 100x updateBlockVerify() not same data +DUR2: 1205792 + +TEST: 100x setBlock() same data +DUR2: 1217796 + +TEST: 100x setBlockVerify() same data +DUR2: 1815424 + +TEST: 100x setBlockVerify() not same data +DUR2: 1812136 +done... + diff --git a/library.json b/library.json index 3b1ceaf..4ecdbf7 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/I2C_EEPROM.git" }, - "version": "1.6.0", + "version": "1.6.1", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/library.properties b/library.properties index 66554b6..bc8ac52 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=I2C_EEPROM -version=1.6.0 +version=1.6.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for I2C EEPROMS diff --git a/test/unit_test_cyclic_store.cpp b/test/unit_test_cyclic_store.cpp index d07da99..e76f451 100644 --- a/test/unit_test_cyclic_store.cpp +++ b/test/unit_test_cyclic_store.cpp @@ -68,7 +68,7 @@ unittest(cyclic_store_empty_begin) I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE); EE.begin(); - + auto miso = Wire.getMiso(I2C_EEPROM_ADDR); miso->push_back(0xff); miso->push_back(0xff); @@ -100,13 +100,12 @@ unittest(cyclic_store_double_page_buffer) miso->push_back(0xff); I2C_eeprom_cyclic_store CS; - assertEqual(true, CS.begin(EE, 32, 4)); + assertTrue(CS.begin(EE, 32, 4)); uint16_t slots; uint32_t writes; - CS.getMetrics(slots, writes); - + assertTrue(CS.getMetrics(slots, writes)); assertEqual(2, slots); assertEqual(0, writes); }