Skip to content

Commit 380fb0b

Browse files
committed
1.8.1 I2C_EEPROM
1 parent fc83b82 commit 380fb0b

File tree

8 files changed

+118
-5
lines changed

8 files changed

+118
-5
lines changed

libraries/I2C_EEPROM/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [1.8.1] - 2023-12-14
10+
- add **uint32_t determineSizeNoWrite()**, kudos to roelandkluit
11+
- add example
12+
- minor edits
13+
14+
915
## [1.8.0] - 2023-11-24 (breaking change)
1016
- simplify **begin()**, remove setting Wire pins from library.
1117
- add **getAddress()**
1218
- update readme.md
1319
- update examples
1420

21+
----
1522

1623
## [1.7.4] - 2023-09-06
1724
- solve #57 add support for WriteProtectPin

libraries/I2C_EEPROM/I2C_eeprom.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: I2C_eeprom.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 1.8.0
4+
// VERSION: 1.8.1
55
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
66
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
77

@@ -305,6 +305,35 @@ uint32_t I2C_eeprom::determineSize(const bool debug)
305305
}
306306

307307

308+
// new 1.8.1 #61
309+
uint32_t I2C_eeprom::determineSizeNoWrite()
310+
{
311+
// try to read a byte to see if connected
312+
if (!isConnected()) return 0;
313+
314+
bool addressSize = _isAddressSizeTwoWords;
315+
byte dummyVal = 0;
316+
uint32_t lastOkSize = 0;
317+
318+
for (uint32_t size = 128; size <= 65536; size *= 2)
319+
{
320+
_isAddressSizeTwoWords = (size > I2C_DEVICESIZE_24LC16); // == 2048
321+
322+
// Try to read last byte of the block, should return length of 0 when fails
323+
if (readBlock(size - 1, &dummyVal, 1) == 0)
324+
{
325+
_isAddressSizeTwoWords = addressSize;
326+
break;
327+
}
328+
else
329+
{
330+
lastOkSize = size;
331+
}
332+
}
333+
return lastOkSize;
334+
}
335+
336+
308337
uint32_t I2C_eeprom::getDeviceSize()
309338
{
310339
return _deviceSize;

libraries/I2C_EEPROM/I2C_eeprom.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: I2C_eeprom.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 1.8.0
5+
// VERSION: 1.8.1
66
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
77
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
88

@@ -104,6 +104,7 @@ class I2C_eeprom
104104

105105
// Meta data functions
106106
uint32_t determineSize(const bool debug = false);
107+
uint32_t determineSizeNoWrite();
107108
uint32_t getDeviceSize();
108109
uint8_t getPageSize();
109110
uint8_t getPageSize(uint32_t deviceSize);
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// FILE: I2C_eeprom_determineSizeNoWrite.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: test determineSizeNoWrite() function
5+
6+
7+
#include "Wire.h"
8+
#include "I2C_eeprom.h"
9+
10+
11+
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
12+
13+
uint32_t start, diff;
14+
15+
16+
void setup()
17+
{
18+
Serial.begin(115200);
19+
while (!Serial); // wait for Serial port to connect. Needed for Leonardo only
20+
Serial.println(__FILE__);
21+
Serial.print("I2C_EEPROM_VERSION: ");
22+
Serial.println(I2C_EEPROM_VERSION);
23+
24+
Wire.begin();
25+
26+
ee.begin();
27+
if (! ee.isConnected())
28+
{
29+
Serial.println("ERROR: Can't find eeprom\nstopped...");
30+
while (1);
31+
}
32+
33+
Serial.println("\nDetermine size no write");
34+
delay(100);
35+
36+
start = micros();
37+
uint32_t size = ee.determineSizeNoWrite();
38+
diff = micros() - start;
39+
Serial.print("TIME: ");
40+
Serial.print(diff);
41+
Serial.println(" us.");
42+
if (size == 0)
43+
{
44+
Serial.println("SIZE: could not determine size");
45+
}
46+
else if (size > 1024)
47+
{
48+
Serial.print("SIZE: ");
49+
Serial.print(size / 1024);
50+
Serial.println(" KB.");
51+
}
52+
else
53+
{
54+
Serial.print("SIZE: ");
55+
Serial.print(size);
56+
Serial.println(" bytes.");
57+
}
58+
59+
Serial.print("PAGE: ");
60+
uint8_t pageSize = ee.getPageSize(size);
61+
Serial.print(pageSize);
62+
Serial.println(" bytes.");
63+
64+
Serial.println("Done...");
65+
}
66+
67+
68+
void loop()
69+
{
70+
}
71+
72+
73+
// -- END OF FILE --

libraries/I2C_EEPROM/keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ updateByteVerify KEYWORD2
3030
updateBlockVerify KEYWORD2
3131

3232
determineSize KEYWORD2
33+
determineSizeNoWrite KEYWORD2
3334
getDeviceSize KEYWORD2
3435
getPageSize KEYWORD2
3536
getLastWrite KEYWORD2

libraries/I2C_EEPROM/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
1717
},
18-
"version": "1.8.0",
18+
"version": "1.8.1",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/I2C_EEPROM/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=I2C_EEPROM
2-
version=1.8.0
2+
version=1.8.1
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Library for I2C EEPROMS

libraries/I2C_EEPROM/readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Same as write and update functions above. Returns true if successful, false indi
139139
- **uint8_t getPageSize()** idem
140140
- **uint8_t getPageSize(uint32_t deviceSize)** idem
141141
- **uint32_t getLastWrite()** idem
142+
- **uint32_t determineSizeNoWrite()** function that determines the size of the EEPROM
143+
by detecting when a selected memory address is not readable. (new in 1.8.1).
142144
- **uint32_t determineSize(bool debug = false)**
143145
function that determines the size of the EEPROM by detecting when a memory address
144146
is folded upon memory address 0.
@@ -147,7 +149,7 @@ The debug flag prints some output to Serial.
147149

148150
**Warning**: this function has changed (again) in 1.4.0
149151

150-
Test results
152+
Test results **determineSize()**
151153

152154
| Type | returns | Memory | Page Size | Notes |
153155
|:--------|:--------|:---------|:---------:|:------|

0 commit comments

Comments
 (0)