This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
EEPROM_iteration.ino
94 lines (66 loc) · 2.48 KB
/
EEPROM_iteration.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/******************************************************************************************************************************************
EEPROM_iteration.ino
For STM32 using Flash emulated-EEPROM
The FlashStorage_STM32 library aims to provide a convenient way to store and retrieve user's data using the non-volatile flash memory
of STM32F/L/H/G/WB/MP1. It's using the buffered read and write to minimize the access to Flash.
It now supports writing and reading the whole object, not just byte-and-byte.
Inspired by Cristian Maglie's FlashStorage (https://github.com/cmaglie/FlashStorage)
Built by Khoi Hoang https://github.com/khoih-prog/FlashStorage_STM32
Licensed under MIT license
******************************************************************************************************************************************/
/***
eeprom_iteration example.
A set of example snippets highlighting the simplest methods for traversing the EEPROM.
Running this sketch is not necessary, this is simply highlighting certain programming methods.
Written by Christopher Andrews 2015
Released under MIT licence.
***/
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include <FlashStorage_STM32.h>
void setup()
{
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStart EEPROM_iteration on "));
Serial.println(BOARD_NAME);
Serial.println(FLASH_STORAGE_STM32_VERSION);
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
/***
Iterate the EEPROM using a for loop.
***/
for (int index = 0 ; index < EEPROM.length() ; index++)
{
// Add one to each cell in the EEPROM
EEPROM.write(index, EEPROM.read(index) + 1);
}
EEPROM.commit();
Serial.println("Done for loop");
/***
Iterate the EEPROM using a while loop.
***/
int index = 0;
while (index < EEPROM.length())
{
//Add one to each cell in the EEPROM
// Add one to each cell in the EEPROM
EEPROM.write(index, EEPROM.read(index) + 1);
index++;
}
EEPROM.commit();
Serial.println("Done while loop");
/***
Iterate the EEPROM using a do-while loop.
***/
index = 0; //Used 'idx' to avoid name conflict with 'index' above.
do
{
// Add one to each cell in the EEPROM
EEPROM.write(index, EEPROM.read(index) + 1);
index++;
} while (index < EEPROM.length());
EEPROM.commit();
Serial.println("Done do-while loop");
} //End of setup function.
void loop() {}