Skip to content

Commit 264c9e4

Browse files
committed
Roll back to v1.0.14
Rolling back to v1 because v2/v3 have problems.
1 parent 187dba8 commit 264c9e4

File tree

12 files changed

+1173
-568
lines changed

12 files changed

+1173
-568
lines changed

README.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
SparkFun External EEPROM Arduino Library
22
===========================================================
33

4-
![SparkFun Qwiic EEPROM](https://cdn.sparkfun.com//assets/parts/1/7/7/0/1/18355-SparkFun_Qwiic_EEPROM_Breakout_-_512Kbit-01.jpg)
4+
![SparkFun Qwiic EEPROM](https://cdn.sparkfun.com//assets/parts/1/3/0/0/8/14764-Qwiic_EEPROM_-_512Kbit-01.jpg)
55

6-
[*SparkFun Qwiic EEPROM (COM-18355)*](https://www.sparkfun.com/products/18355)
6+
[*SparkFun Qwiic EEPROM (SPX-14764)*](https://www.sparkfun.com/products/14764)
77

8-
A simple-to-use I2C library for talking to any EEPROM. It uses the same template system found in the Arduino EEPROM library so you can use the same get() and put() functions.
8+
A simple to use I2C library for talking to any EEPROM. It uses the same template system found in the Arduino EEPROM library so you can use the same get() and put() functions.
99

10-
The device-specific specs (overall size, page size, write times, etc) are auto-detected. This library works with all types and allows the various settings to be set at runtime. All read and write restrictions associated with pages are taken care of. You can access the external memory as if it was contiguous.
10+
Various external EEPROMs have various interface specs (overall size, page size, write times, etc). This library works with all types and allows the various settings to be set at runtime. All read and write restrictions associated with pages are taken care of. You can access the external memory as if it was contiguous.
1111

12-
Best used with the Qwiic EEPROM: https://www.sparkfun.com/products/18355
12+
Best used with the Qwiic EEPROM: https://www.sparkfun.com/products/14764
1313

1414
This library can be installed via the Arduino Library manager. Search for **SparkFun External EEPROM**.
1515

16-
The method for autodetection is as follows. The original data on the EEPROM is maintained once autodetection is complete:
17-
18-
* Address Bytes: Smaller EEPROMs use one address byte and larger EEPROMs use 2 address bytes. The auto-detection routine attempts to read a byte and then write a new byte. If the read/write fails, the address byte count is increased and a write attempt is tried again. Once the correct number of address bytes is detected, the original value is written back to EEPROM.
19-
20-
* Page Size: 256 bytes of EEPROM are read individually (to avoid page reads). Then, new bytes are generated that are random *and* different from the original data. The new bytes are written to EEPROM in increasing page size tests (8 bytes, then 16, etc) until the data does not match. Then the original data is written back to the EEPROM. Note: The page size may be reported as 32 bytes when the actual page size is larger. This is because of the size of the I2C buffer available on your microcontroller's Arduino core's Wire implementation. On some platforms (such as Arduino Uno) the I2C write buffer is 32 bytes. Once the two write bytes are removed, that leaves only 30 bytes available for sequential reads/writes. For maximum write speeds, use a platform that has a larger buffer than the page size of the EEPROM you are using.
21-
22-
* Memory Size: Once address bytes and page size are determined, single bytes are read, then written, then checked at the end of the potential EEPROM space. For example, byte 65535 is read for its original value and stored. Then a new, different value is written to location 65535. If the read/write fails, we know the EEPROM is one size down (32768 bytes, aka 24XX256).
23-
24-
* Page write time: This setting is not detected at begin(). All EEPROMs have a max write time of 5ms. Testing with a logic analyzer has shown that all EEPROMs respect this max and have an average of ~4.5ms for a page write. Attempting to trim the page write time lower than 5ms is much less worthwhile than using up a properly sized page size setting with an adequately sized I2C write buffer. In other words, read and write as many bytes as the page size can handle, don't worry about setting the page write time to 4ms or 5ms. Note: The 24XXM02 has a 10ms max page write time.
25-
2616
Want to help? Please do! We are always looking for ways to improve and build out features of this library.
2717

2818
Thanks to:

examples/Example1_BasicReadWrite/Example1_BasicReadWrite.ino

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,15 @@ void setup()
3939
}
4040
Serial.println("Memory detected!");
4141

42-
uint32_t eepromSizeBytes = myMem.getMemorySizeBytes();
43-
Serial.print("Detected EEPROM size (bytes): ");
44-
Serial.print(eepromSizeBytes);
45-
Serial.print(" - EEPROM Type: 24XX");
46-
if (eepromSizeBytes == 16)
47-
Serial.print("00");
48-
else
49-
{
50-
if ((eepromSizeBytes * 8 / 1024) < 10) Serial.print("0");
51-
Serial.print(eepromSizeBytes * 8 / 1024);
52-
}
53-
Serial.println();
54-
55-
Serial.print("Detected number of address bytes: ");
56-
Serial.println(myMem.getAddressBytes());
57-
58-
Serial.print("Detected pageSizeBytes: ");
59-
Serial.println(myMem.getPageSizeBytes());
42+
Serial.print("Mem size in bytes: ");
43+
Serial.println(myMem.length());
6044

6145
//Yes you can read and write bytes, but you shouldn't!
6246
byte myValue1 = 200;
6347
myMem.write(0, myValue1); //(location, data)
6448

6549
byte myRead1 = myMem.read(0);
66-
Serial.print("I read (should be 200): ");
50+
Serial.print("I read: ");
6751
Serial.println(myRead1);
6852

6953
//You should use gets and puts. This will automatically and correctly arrange
@@ -72,14 +56,14 @@ void setup()
7256
myMem.put(10, myValue2); //(location, data)
7357
int myRead2;
7458
myMem.get(10, myRead2); //location to read, thing to put data into
75-
Serial.print("I read (should be -366): ");
59+
Serial.print("I read: ");
7660
Serial.println(myRead2);
7761

7862
float myValue3 = -7.35;
7963
myMem.put(20, myValue3); //(location, data)
8064
float myRead3;
8165
myMem.get(20, myRead3); //location to read, thing to put data into
82-
Serial.print("I read (should be -7.35): ");
66+
Serial.print("I read: ");
8367
Serial.println(myRead3);
8468

8569
String myString = "Hi, I am just a simple test string";
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Read and write settings and calibration data to an external I2C EEPROM
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: December 11th, 2019
6+
License: This code is public domain but you buy me a beer if you use this
7+
and we meet someday (Beerware license).
8+
Feel like supporting our work? Buy a board from SparkFun!
9+
https://www.sparkfun.com/products/14764
10+
11+
This example demonstrates how to set the various settings for a given EEPROM.
12+
Read the datasheet! Each EEPROM will have specific values for:
13+
Overall EEPROM size in bytes (512kbit = 65536, 256kbit = 32768)
14+
Bytes per page write (64 and 128 are common)
15+
Whether write polling is supported
16+
17+
The I2C EEPROM should have all its ADR pins set to GND (0). This is default
18+
on the Qwiic board.
19+
20+
Hardware Connections:
21+
Plug the SparkFun Qwiic EEPROM to an Uno, Artemis, or other Qwiic equipped board
22+
Load this sketch
23+
Open output window at 115200bps
24+
*/
25+
26+
#include <Wire.h>
27+
28+
#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM
29+
ExternalEEPROM myMem;
30+
31+
void setup()
32+
{
33+
Serial.begin(115200);
34+
delay(10);
35+
Serial.println("I2C EEPROM example");
36+
37+
Wire.begin();
38+
Wire.setClock(400000); //Most EEPROMs can run 400kHz and higher
39+
40+
if (myMem.begin() == false)
41+
{
42+
Serial.println("No memory detected. Freezing.");
43+
while (1);
44+
}
45+
Serial.println("Memory detected!");
46+
47+
//Set settings for this EEPROM
48+
myMem.setMemorySize(512 * 1024 / 8); //In bytes. 512kbit = 64kbyte
49+
myMem.setPageSize(128); //In bytes. Has 128 byte page size.
50+
myMem.enablePollForWriteComplete(); //Supports I2C polling of write completion
51+
myMem.setPageWriteTime(5); //5 ms max write time
52+
53+
Serial.print("Mem size in bytes: ");
54+
Serial.println(myMem.length());
55+
56+
float myValue3 = -7.35;
57+
myMem.put(20, myValue3); //(location, data)
58+
float myRead3;
59+
myMem.get(20, myRead3); //location to read, thing to put data into
60+
Serial.print("I read: ");
61+
Serial.println(myRead3);
62+
63+
}
64+
65+
void loop()
66+
{
67+
68+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Read and write settings and calibration data to an external I2C EEPROM
3+
By: Nathan Seidle
4+
SparkFun Electronics
5+
Date: December 11th, 2019
6+
License: This code is public domain but you buy me a beer if you use this
7+
and we meet someday (Beerware license).
8+
Feel like supporting our work? Buy a board from SparkFun!
9+
https://www.sparkfun.com/products/14764
10+
11+
This example demonstrates how to pass a custom EEPROM address and Wire.
12+
13+
This library supports EEPROMs with any I2C address and
14+
any Wire hardware (Wire1, Wire2, etc) by passing them into begin.
15+
16+
For this example the I2C EEPROM should have all its ADR0 to VCC,
17+
ADR1 to GND, and ADR2 to GND.
18+
19+
Hardware Connections:
20+
I used an Artemis for this example. Make sure to connect the PTH of Qwiic EEPROM to the pins of the seconday I2C bus.
21+
22+
pin 0 on Artemis RedBoard = SDA on Qwiic EEPROM
23+
pin 6 = SCL
24+
GND to GND
25+
3.3V to 3.3V
26+
27+
Load this sketch
28+
Open output window at 115200bps
29+
*/
30+
31+
#include <Wire.h>
32+
33+
#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM
34+
ExternalEEPROM myMem;
35+
36+
void setup()
37+
{
38+
Serial.begin(115200);
39+
delay(10);
40+
Serial.println("I2C EEPROM example");
41+
42+
// Wire1.setClock(400000); //set I2C communication to 400kHz
43+
Wire1.begin();
44+
45+
#define EEPROM_ADDRESS 0b1010001 //0b1010(A2 A1 A0): A standard I2C EEPROM with the ADR0 bit set to VCC
46+
47+
//Connect to a EEPROM with ADR0 set to VCC and use the Wire1 hardware to talk to the EEPROM
48+
if (myMem.begin(EEPROM_ADDRESS, Wire1) == false) //And Uno will fail to compile here
49+
{
50+
Serial.println("No memory detected. Freezing.");
51+
while (1);
52+
}
53+
Serial.println("Memory detected!");
54+
55+
float myValue3 = -7.35;
56+
myMem.put(20, myValue3); //(location, data)
57+
float myRead3;
58+
myMem.get(20, myRead3); //location to read, thing to put data into
59+
Serial.print("I read: ");
60+
Serial.println(myRead3);
61+
}
62+
63+
void loop()
64+
{
65+
66+
}

0 commit comments

Comments
 (0)