Skip to content

Commit 81ee950

Browse files
authored
Merge pull request #75 from sparkfun/eepromRewrite
EEPROM rewrite
2 parents f647a3c + 217a39b commit 81ee950

File tree

4 files changed

+230
-319
lines changed

4 files changed

+230
-319
lines changed

libraries/EEPROM/examples/Example1_GetPut/Example1_GetPut.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
void setup()
2727
{
28-
Serial.begin(9600);
28+
Serial.begin(115200);
2929
Serial.println("EEPROM Examples");
3030

3131
byte myValue1 = 200;

libraries/EEPROM/examples/Example2_AllFunctions/Example2_AllFunctions.ino

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323

2424
void setup()
2525
{
26-
Serial.begin(9600);
26+
Serial.begin(115200);
2727
Serial.println("EEPROM Examples");
2828

2929
randomSeed(analogRead(A0));
3030

3131
long startTime;
3232
long endTime;
33-
uint16_t randomLocation;
33+
int randomLocation;
3434

3535
//Test erase time
3636
startTime = millis();
@@ -53,6 +53,12 @@ void setup()
5353

5454
Serial.printf("Write byte time: %dms\n", endTime - startTime);
5555

56+
startTime = millis();
57+
EEPROM.write(randomLocation, myValue1); //(location, data)
58+
endTime = millis();
59+
60+
Serial.printf("Write identical byte to same location (should be ~1): %dms\n", endTime - startTime);
61+
5662
byte response1 = EEPROM.read(randomLocation);
5763
byte response2 = EEPROM.read(randomLocation + 1);
5864
Serial.printf("Location %d should be %d: %d\n\r", randomLocation, myValue1, response1);
@@ -106,8 +112,8 @@ void setup()
106112
uint32_t myValue8 = 241544;
107113
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
108114

109-
EEPROM.update(randomLocation, myValue7);
110-
EEPROM.update(randomLocation + 4, myValue8);
115+
EEPROM.put(randomLocation, myValue7);
116+
EEPROM.put(randomLocation + 4, myValue8);
111117

112118
int32_t response7;
113119
uint32_t response8;
@@ -124,8 +130,8 @@ void setup()
124130
float myValue10 = 5.22;
125131
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
126132

127-
EEPROM.update(randomLocation, myValue9);
128-
EEPROM.update(randomLocation + 4, myValue10);
133+
EEPROM.put(randomLocation, myValue9);
134+
EEPROM.put(randomLocation + 4, myValue10);
129135

130136
float response9;
131137
float response10;
@@ -143,20 +149,50 @@ void setup()
143149
Serial.printf("Size of double: %d\n", sizeof(double));
144150
double myValue11 = -290.3485723409857;
145151
double myValue12 = 384.95734987;
152+
double myValue13 = 917.14159;
153+
double myValue14 = 254.8877;
146154
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
147155

148-
EEPROM.update(randomLocation, myValue11);
149-
EEPROM.update(randomLocation + 8, myValue12);
156+
startTime = millis();
157+
EEPROM.put(randomLocation, myValue11);
158+
endTime = millis();
159+
Serial.printf("Time to record 64-bits: %dms\n", endTime - startTime);
160+
161+
EEPROM.put(randomLocation + 8, myValue12);
162+
EEPROM.put(EEPROM.length() - sizeof(myValue13), myValue13); //Test end of EEPROM space
150163

151164
double response11;
152165
double response12;
166+
double response13;
153167
EEPROM.get(randomLocation, response11);
154168
EEPROM.get(randomLocation + 8, response12);
169+
EEPROM.get(EEPROM.length() - sizeof(myValue13), response13);
155170
Serial.printf("Location %d should be %lf: %lf\n", randomLocation, myValue11, response11);
156171
Serial.printf("Location %d should be %lf: %lf\n", randomLocation + 8, myValue12, response12);
172+
Serial.printf("Edge of EEPROM %d should be %lf: %lf\n", EEPROM.length() - sizeof(myValue13), myValue13, response13);
173+
174+
double response14;
175+
EEPROM.put(EEPROM.length() - sizeof(myValue14), myValue14); //Test the re-write of a spot
176+
EEPROM.get(EEPROM.length() - sizeof(myValue14), response14);
177+
Serial.printf("Rewrite of %d should be %lf: %lf\n", EEPROM.length() - sizeof(myValue14), myValue14, response14);
157178
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
158179

159-
Serial.println();
180+
Serial.println("");
181+
Serial.println("String test");
182+
183+
//String write test
184+
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
185+
char myString[19] = "How are you today?";
186+
randomLocation = random(0, AP3_FLASH_EEPROM_SIZE);
187+
EEPROM.put(randomLocation, myString);
188+
189+
char readMy[19];
190+
EEPROM.get(randomLocation, readMy);
191+
Serial.printf("Location %d string should read 'How are you today?': ", randomLocation);
192+
Serial.println(readMy);
193+
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
194+
195+
Serial.println("");
160196
Serial.print("Flash Contents:");
161197
for (uint16_t x = 0; x < 8 * 4; x += 4)
162198
{

0 commit comments

Comments
 (0)