From 380fb0b5c641b655e0ddce616a20a27d9bd77a53 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Thu, 14 Dec 2023 11:58:08 +0100 Subject: [PATCH] 1.8.1 I2C_EEPROM --- libraries/I2C_EEPROM/CHANGELOG.md | 7 ++ libraries/I2C_EEPROM/I2C_eeprom.cpp | 31 +++++++- libraries/I2C_EEPROM/I2C_eeprom.h | 3 +- .../I2C_eeprom_determineSizeNoWrite.ino | 73 +++++++++++++++++++ libraries/I2C_EEPROM/keywords.txt | 1 + libraries/I2C_EEPROM/library.json | 2 +- libraries/I2C_EEPROM/library.properties | 2 +- libraries/I2C_EEPROM/readme.md | 4 +- 8 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 libraries/I2C_EEPROM/examples/I2C_eeprom_determineSizeNoWrite/I2C_eeprom_determineSizeNoWrite.ino diff --git a/libraries/I2C_EEPROM/CHANGELOG.md b/libraries/I2C_EEPROM/CHANGELOG.md index 7d6da9c5..ccb1cb6a 100644 --- a/libraries/I2C_EEPROM/CHANGELOG.md +++ b/libraries/I2C_EEPROM/CHANGELOG.md @@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.8.1] - 2023-12-14 +- add **uint32_t determineSizeNoWrite()**, kudos to roelandkluit +- add example +- minor edits + + ## [1.8.0] - 2023-11-24 (breaking change) - simplify **begin()**, remove setting Wire pins from library. - add **getAddress()** - update readme.md - update examples +---- ## [1.7.4] - 2023-09-06 - solve #57 add support for WriteProtectPin diff --git a/libraries/I2C_EEPROM/I2C_eeprom.cpp b/libraries/I2C_EEPROM/I2C_eeprom.cpp index 7704d80d..9078de37 100644 --- a/libraries/I2C_EEPROM/I2C_eeprom.cpp +++ b/libraries/I2C_EEPROM/I2C_eeprom.cpp @@ -1,7 +1,7 @@ // // FILE: I2C_eeprom.cpp // AUTHOR: Rob Tillaart -// VERSION: 1.8.0 +// VERSION: 1.8.1 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git @@ -305,6 +305,35 @@ uint32_t I2C_eeprom::determineSize(const bool debug) } +// new 1.8.1 #61 +uint32_t I2C_eeprom::determineSizeNoWrite() +{ + // try to read a byte to see if connected + if (!isConnected()) return 0; + + bool addressSize = _isAddressSizeTwoWords; + byte dummyVal = 0; + uint32_t lastOkSize = 0; + + for (uint32_t size = 128; size <= 65536; size *= 2) + { + _isAddressSizeTwoWords = (size > I2C_DEVICESIZE_24LC16); // == 2048 + + // Try to read last byte of the block, should return length of 0 when fails + if (readBlock(size - 1, &dummyVal, 1) == 0) + { + _isAddressSizeTwoWords = addressSize; + break; + } + else + { + lastOkSize = size; + } + } + return lastOkSize; +} + + uint32_t I2C_eeprom::getDeviceSize() { return _deviceSize; diff --git a/libraries/I2C_EEPROM/I2C_eeprom.h b/libraries/I2C_EEPROM/I2C_eeprom.h index 8934264c..16d5c197 100644 --- a/libraries/I2C_EEPROM/I2C_eeprom.h +++ b/libraries/I2C_EEPROM/I2C_eeprom.h @@ -2,7 +2,7 @@ // // FILE: I2C_eeprom.h // AUTHOR: Rob Tillaart -// VERSION: 1.8.0 +// VERSION: 1.8.1 // PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al. // URL: https://github.com/RobTillaart/I2C_EEPROM.git @@ -104,6 +104,7 @@ public: // Meta data functions uint32_t determineSize(const bool debug = false); + uint32_t determineSizeNoWrite(); uint32_t getDeviceSize(); uint8_t getPageSize(); uint8_t getPageSize(uint32_t deviceSize); diff --git a/libraries/I2C_EEPROM/examples/I2C_eeprom_determineSizeNoWrite/I2C_eeprom_determineSizeNoWrite.ino b/libraries/I2C_EEPROM/examples/I2C_eeprom_determineSizeNoWrite/I2C_eeprom_determineSizeNoWrite.ino new file mode 100644 index 00000000..f48cbf9b --- /dev/null +++ b/libraries/I2C_EEPROM/examples/I2C_eeprom_determineSizeNoWrite/I2C_eeprom_determineSizeNoWrite.ino @@ -0,0 +1,73 @@ +// +// FILE: I2C_eeprom_determineSizeNoWrite.ino +// AUTHOR: Rob Tillaart +// PURPOSE: test determineSizeNoWrite() function + + +#include "Wire.h" +#include "I2C_eeprom.h" + + +I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256); + +uint32_t start, diff; + + +void setup() +{ + Serial.begin(115200); + while (!Serial); // wait for Serial port to connect. Needed for Leonardo only + Serial.println(__FILE__); + Serial.print("I2C_EEPROM_VERSION: "); + Serial.println(I2C_EEPROM_VERSION); + + Wire.begin(); + + ee.begin(); + if (! ee.isConnected()) + { + Serial.println("ERROR: Can't find eeprom\nstopped..."); + while (1); + } + + Serial.println("\nDetermine size no write"); + delay(100); + + start = micros(); + uint32_t size = ee.determineSizeNoWrite(); + diff = micros() - start; + Serial.print("TIME: "); + Serial.print(diff); + Serial.println(" us."); + if (size == 0) + { + Serial.println("SIZE: could not determine size"); + } + else if (size > 1024) + { + Serial.print("SIZE: "); + Serial.print(size / 1024); + Serial.println(" KB."); + } + else + { + Serial.print("SIZE: "); + Serial.print(size); + Serial.println(" bytes."); + } + + Serial.print("PAGE: "); + uint8_t pageSize = ee.getPageSize(size); + Serial.print(pageSize); + Serial.println(" bytes."); + + Serial.println("Done..."); +} + + +void loop() +{ +} + + +// -- END OF FILE -- diff --git a/libraries/I2C_EEPROM/keywords.txt b/libraries/I2C_EEPROM/keywords.txt index 4dbd71fc..fe6cfb1a 100644 --- a/libraries/I2C_EEPROM/keywords.txt +++ b/libraries/I2C_EEPROM/keywords.txt @@ -30,6 +30,7 @@ updateByteVerify KEYWORD2 updateBlockVerify KEYWORD2 determineSize KEYWORD2 +determineSizeNoWrite KEYWORD2 getDeviceSize KEYWORD2 getPageSize KEYWORD2 getLastWrite KEYWORD2 diff --git a/libraries/I2C_EEPROM/library.json b/libraries/I2C_EEPROM/library.json index c311c75d..b6237152 100644 --- a/libraries/I2C_EEPROM/library.json +++ b/libraries/I2C_EEPROM/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/I2C_EEPROM.git" }, - "version": "1.8.0", + "version": "1.8.1", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/I2C_EEPROM/library.properties b/libraries/I2C_EEPROM/library.properties index b17864c9..cf35374f 100644 --- a/libraries/I2C_EEPROM/library.properties +++ b/libraries/I2C_EEPROM/library.properties @@ -1,5 +1,5 @@ name=I2C_EEPROM -version=1.8.0 +version=1.8.1 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for I2C EEPROMS diff --git a/libraries/I2C_EEPROM/readme.md b/libraries/I2C_EEPROM/readme.md index 3558a68c..77ce185f 100644 --- a/libraries/I2C_EEPROM/readme.md +++ b/libraries/I2C_EEPROM/readme.md @@ -139,6 +139,8 @@ Same as write and update functions above. Returns true if successful, false indi - **uint8_t getPageSize()** idem - **uint8_t getPageSize(uint32_t deviceSize)** idem - **uint32_t getLastWrite()** idem +- **uint32_t determineSizeNoWrite()** function that determines the size of the EEPROM +by detecting when a selected memory address is not readable. (new in 1.8.1). - **uint32_t determineSize(bool debug = false)** function that determines the size of the EEPROM by detecting when a memory address is folded upon memory address 0. @@ -147,7 +149,7 @@ The debug flag prints some output to Serial. **Warning**: this function has changed (again) in 1.4.0 -Test results +Test results **determineSize()** | Type | returns | Memory | Page Size | Notes | |:--------|:--------|:---------|:---------:|:------|