Skip to content

Commit 240ebce

Browse files
authored
Merge pull request RobTillaart#54 from aldras/patch-1
Update I2C_eeprom_test.ino
2 parents 37ad83c + 76139cb commit 240ebce

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

libraries/I2C_EEPROM/examples/I2C_eeprom_test/I2C_eeprom_test.ino

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
// Due
1414
// #define SERIAL_OUT SerialUSB
1515

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);
1727

1828
uint32_t start, diff, totals = 0;
1929

@@ -77,7 +87,7 @@ void setup()
7787
SERIAL_OUT.println("\nTEST: write large string readback in small steps");
7888
ee.setBlock(0, 0, 128);
7989
char data2[] = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999A";
80-
ee.writeBlock(10, (uint8_t *) &data2, 100);
90+
ee.writeBlock(10, (uint8_t *) &data2, sizeof(data2));
8191
dumpEEPROM(0, 128);
8292
for (int i = 0; i < 100; i++)
8393
{
@@ -91,7 +101,7 @@ void setup()
91101
SERIAL_OUT.println("\nTEST: check almost endofPage writeBlock");
92102
ee.setBlock(0, 0, 128);
93103
char data3[] = "6666";
94-
ee.writeBlock(60, (uint8_t *) &data3, 2);
104+
ee.writeBlock(60, (uint8_t *) &data3, sizeof(data3));
95105
dumpEEPROM(0, 128);
96106

97107
// SERIAL_OUT.println();
@@ -195,20 +205,59 @@ void loop()
195205

196206
void dumpEEPROM(uint16_t memoryAddress, uint16_t length)
197207
{
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;
201235

202236
byte b = ee.readByte(memoryAddress);
203237
for (int i = 0; i < length; i++)
204238
{
205-
if (memoryAddress % 10 == 0)
239+
char buf[6];
240+
if (memoryAddress % BLOCK_TO_LENGTH == 0)
206241
{
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);
209252
SERIAL_OUT.print(":\t");
210253
}
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);
212261
b = ee.readByte(++memoryAddress);
213262
SERIAL_OUT.print(" ");
214263
}

0 commit comments

Comments
 (0)