13
13
// Due
14
14
// #define SERIAL_OUT SerialUSB
15
15
16
- I2C_eeprom ee (0x50 );
16
+ // for decimal display uncomment below two lines
17
+ #define DISPLAY_DECIMAL
18
+ #define BLOCK_TO_LENGTH 10
19
+
20
+ // for hex display uncomment below two lines
21
+ // #define DISPLAY_HEX
22
+ // #define BLOCK_TO_LENGTH 16
23
+
24
+ #define MEMORY_SIZE 0x2000 // total bytes can be accessed 24LC64 = 0x2000 (maximum address = 0x1FFF)
25
+
26
+ I2C_eeprom ee (0x50 , MEMORY_SIZE);
17
27
18
28
uint32_t start, diff, totals = 0 ;
19
29
@@ -77,7 +87,7 @@ void setup()
77
87
SERIAL_OUT.println (" \n TEST: write large string readback in small steps" );
78
88
ee.setBlock (0 , 0 , 128 );
79
89
char data2[] = " 0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A" ;
80
- ee.writeBlock (10 , (uint8_t *) &data2, 100 );
90
+ ee.writeBlock (10 , (uint8_t *) &data2, sizeof (data2) );
81
91
dumpEEPROM (0 , 128 );
82
92
for (int i = 0 ; i < 100 ; i++)
83
93
{
@@ -91,7 +101,7 @@ void setup()
91
101
SERIAL_OUT.println (" \n TEST: check almost endofPage writeBlock" );
92
102
ee.setBlock (0 , 0 , 128 );
93
103
char data3[] = " 6666" ;
94
- ee.writeBlock (60 , (uint8_t *) &data3, 2 );
104
+ ee.writeBlock (60 , (uint8_t *) &data3, sizeof (data3) );
95
105
dumpEEPROM (0 , 128 );
96
106
97
107
// SERIAL_OUT.println();
@@ -195,20 +205,59 @@ void loop()
195
205
196
206
void dumpEEPROM (uint16_t memoryAddress, uint16_t length)
197
207
{
198
- // block to 10
199
- memoryAddress = memoryAddress / 10 * 10 ;
200
- length = (length + 9 ) / 10 * 10 ;
208
+ #ifdef DISPLAY_DECIMAL
209
+ SERIAL_OUT.print (" \t " );
210
+ #endif
211
+ #ifdef DISPLAY_HEX
212
+ SERIAL_OUT.print (" \t " );
213
+ #endif
214
+ for (int x = 0 ; x < BLOCK_TO_LENGTH; x++) {
215
+ if (x != 0 ) {
216
+ #ifdef DISPLAY_DECIMAL
217
+ SERIAL_OUT.print (" " );
218
+ #endif
219
+ #ifdef DISPLAY_HEX
220
+ SERIAL_OUT.print (" " );
221
+ #endif
222
+ }
223
+ #ifdef DISPLAY_DECIMAL
224
+ SERIAL_OUT.print (x);
225
+ #endif
226
+ #ifdef DISPLAY_HEX
227
+ SERIAL_OUT.print (x,HEX);
228
+ #endif
229
+ }
230
+ SERIAL_OUT.println ();
231
+
232
+ // block to defined length
233
+ memoryAddress = memoryAddress / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
234
+ length = (length + BLOCK_TO_LENGTH - 1 ) / BLOCK_TO_LENGTH * BLOCK_TO_LENGTH;
201
235
202
236
byte b = ee.readByte (memoryAddress);
203
237
for (int i = 0 ; i < length; i++)
204
238
{
205
- if (memoryAddress % 10 == 0 )
239
+ char buf[6 ];
240
+ if (memoryAddress % BLOCK_TO_LENGTH == 0 )
206
241
{
207
- SERIAL_OUT.println ();
208
- SERIAL_OUT.print (memoryAddress);
242
+ if (i != 0 ) {
243
+ SERIAL_OUT.println ();
244
+ }
245
+ #ifdef DISPLAY_DECIMAL
246
+ sprintf (buf, " %05d" , memoryAddress);
247
+ #endif
248
+ #ifdef DISPLAY_HEX
249
+ sprintf (buf, " %04X" , memoryAddress);
250
+ #endif
251
+ SERIAL_OUT.print (buf);
209
252
SERIAL_OUT.print (" :\t " );
210
253
}
211
- SERIAL_OUT.print (b);
254
+ #ifdef DISPLAY_DECIMAL
255
+ sprintf (buf, " %03d" , b);
256
+ #endif
257
+ #ifdef DISPLAY_HEX
258
+ sprintf (buf, " %02X" , b);
259
+ #endif
260
+ SERIAL_OUT.print (buf);
212
261
b = ee.readByte (++memoryAddress);
213
262
SERIAL_OUT.print (" " );
214
263
}
0 commit comments