1.8.1 I2C_EEPROM

This commit is contained in:
Rob Tillaart 2023-12-14 11:58:08 +01:00
parent fc83b82d66
commit 380fb0b5c6
8 changed files with 118 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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 --

View File

@ -30,6 +30,7 @@ updateByteVerify KEYWORD2
updateBlockVerify KEYWORD2
determineSize KEYWORD2
determineSizeNoWrite KEYWORD2
getDeviceSize KEYWORD2
getPageSize KEYWORD2
getLastWrite KEYWORD2

View File

@ -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": "*",

View File

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

View File

@ -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 |
|:--------|:--------|:---------|:---------:|:------|