12 const uint32_t totalKBytes = 32;
15 const uint8_t btnStart = 6;
20 pinMode(btnStart, INPUT_PULLUP);
24 bool channelInsert =
false;
25 Serial.println(F(
"Select the number of Wire channel use the eeprom"));
26 Serial.println(F(
"0 = Wire"));
27 Serial.println(F(
"1 = Wire1"));
28 Serial.println(F(
"...."));
29 Serial.println(F(
"x = WIRE_INTERFACES_COUNT"));
32 if (Serial.available()) {
33 char I2Cchannel = Serial.read();
36 if ((I2Cchannel >
'0') && (I2Cchannel < (
'0' + WIRE_INTERFACES_COUNT))) {
40 switch ((I2Cchannel -
'0')) {
43 Serial.println(F(
"Using the default Wire interface"));
48 Serial.println(F(
"Using the Wire1 interface"));
75 Serial.println(F(
"A wrong channel has been inserted (Arduino manage max 5)"));
79 }
while (!channelInsert);
82 Serial.print(F(
"extEEPROM.begin() failed, status = "));
83 Serial.println(eepStatus);
87 Serial.println(F(
"Started !!"));
106 void eeWrite(uint8_t chunk)
111 Serial.println(F(
"Writing..."));
112 uint32_t msStart = millis();
114 for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
115 if ( (addr & 0xFFF) == 0 ) {
116 Serial.println(addr);
118 for (uint8_t c = 0; c < chunk; c += 4) {
119 data[c + 0] = val >> 24;
120 data[c + 1] = val >> 16;
121 data[c + 2] = val >> 8;
127 uint32_t msLapse = millis() - msStart;
128 Serial.print(F(
"Write lapse: "));
129 Serial.print(msLapse);
130 Serial.println(F(
" ms"));
134 void eeRead(uint8_t chunk)
138 uint32_t val = 0, testVal;
139 Serial.println(F(
"Reading..."));
140 uint32_t msStart = millis();
142 for (uint32_t addr = 0; addr < totalKBytes * 1024; addr += chunk) {
143 if ( (addr & 0xFFF) == 0 ) {
144 Serial.println(addr);
147 for (uint8_t c = 0; c < chunk; c += 4) {
148 testVal = ((uint32_t)
data[c + 0] << 24) + ((uint32_t)
data[c + 1] << 16) + ((
149 uint32_t)
data[c + 2] << 8) + (uint32_t)
data[c + 3];
150 if (testVal != val) {
151 Serial.print(F(
"Error @ addr "));
152 Serial.print(addr + c);
153 Serial.print(F(
" Expected "));
155 Serial.print(F(
" Read "));
156 Serial.print(testVal);
157 Serial.print(F(
" 0x"));
158 Serial.println(testVal, HEX);
163 uint32_t msLapse = millis() - msStart;
164 Serial.print(F(
"Last value: "));
166 Serial.print(F(
" Read lapse: "));
167 Serial.print(msLapse);
168 Serial.println(F(
" ms"));
172 void eeErase(uint8_t chunk, uint32_t startAddr, uint32_t endAddr)
176 Serial.println(F(
"Erasing..."));
177 for (
int i = 0; i < chunk; i++) {
180 uint32_t msStart = millis();
182 for (uint32_t a = startAddr; a <= endAddr; a += chunk) {
183 if ( (a & 0xFFF) == 0 ) {
188 uint32_t msLapse = millis() - msStart;
189 Serial.print(F(
"Erase lapse: "));
190 Serial.print(msLapse);
191 Serial.print(F(
" ms"));
196 void dump(uint32_t startAddr, uint32_t nBytes)
198 Serial.print(F(
"EEPROM DUMP 0x"));
199 Serial.print(startAddr, HEX);
200 Serial.print(F(
" 0x"));
201 Serial.print(nBytes, HEX);
202 Serial.print(F(
" "));
203 Serial.print(startAddr);
204 Serial.print(F(
" "));
205 Serial.println(nBytes);
206 uint32_t nRows = (nBytes + 15) >> 4;
209 for (uint32_t r = 0; r < nRows; r++) {
210 uint32_t a = startAddr + 16 * r;
212 Serial.print(F(
"0x"));
213 if ( a < 16 * 16 * 16 ) {
214 Serial.print(F(
"0"));
217 Serial.print(F(
"0"));
220 Serial.print(F(
"0"));
222 Serial.print(a, HEX);
223 Serial.print(F(
" "));
224 for (
int c = 0; c < 16; c++ ) {
226 Serial.print(F(
"0"));
227 Serial.print(d[c], HEX);
228 Serial.print( c == 7 ?
" " :
" ");
231 Serial.println(F(
""));