19 #include "extEEPROM.h"
21 extEEPROM myEEPROM(kbits_256, 1, 64, 0x57);
25 SerialUSB.begin(115200);
32 SerialUSB.println(F(
"I2C Problem"));
36 F(
"EEPROM Memory commands: read:(a)(l)(r) , write:(a)(d)(w), next read data (n)"));
37 SerialUSB.println(F(
"- Commands TO PRESS:"));
38 SerialUSB.println(F(
"\t a : memory address to read / write"));
39 SerialUSB.println(F(
"\t d : data to write"));
40 SerialUSB.println(F(
"\t l : data to write"));
41 SerialUSB.println(F(
"\t r : read command"));
42 SerialUSB.println(F(
"\t w : write command"));
45 unsigned long address = 0;
46 const unsigned int maxDataSize = 1024;
48 byte data[maxDataSize] = {
'p',
'i',
'p',
'p',
'o'};
49 unsigned int dataSize = 5;
51 void eprom_read_write(
bool write)
55 i2cStat = myEEPROM.
write(address,
data, dataSize);
57 memset(
data, 0, maxDataSize);
58 i2cStat = myEEPROM.
read(address,
data, dataSize);
62 SerialUSB.print(F(
"I2C Problem: "));
63 if ( i2cStat == EEPROM_ADDR_ERR) {
64 SerialUSB.println(F(
"Wrong address"));
66 SerialUSB.print(F(
"I2C error: "));
67 SerialUSB.print(i2cStat);
68 SerialUSB.println(F(
""));
74 void parse(
char inChar)
76 const char addr_len = 5;
77 char addr_char[addr_len] =
"";
78 const char data_len = 3;
79 char data_char[data_len] =
"";
80 char size_char[data_len] =
"";
81 char inc = 0, i = 0, j = 0;
85 SerialUSB.print(F(
"Insert Address as 4 Hex chars (without '0x'): "));
88 while (SerialUSB.available() <= 0)
90 inc = SerialUSB.read();
99 address = (
unsigned long)strtol(addr_char, NULL, 16);
100 SerialUSB.println(address);
104 SerialUSB.print(F(
"Insert Hex data sequence (without '0x'), return to enter: "));
105 memset(
data, 0, maxDataSize);
107 while (SerialUSB.available() <= 0)
109 inc = SerialUSB.read();
113 if (inc ==
'\r' || inc ==
'\n') {
117 if (inc >=
'a' && inc <=
'f') {
118 data[j] += inc -
'a' + 10;
119 }
else if (inc >=
'A' && inc <=
'F') {
120 data[j] += inc -
'A' + 10;
121 }
else if (inc >=
'0' && inc <=
'9') {
122 data[j] += inc -
'0';
135 SerialUSB.println(dataSize);
136 SerialUSB.println(F(
""));
139 SerialUSB.print(F(
"Insert data len as 2 Hex chars (without '0x'): "));
141 while (SerialUSB.available() <= 0)
143 inc = SerialUSB.read();
155 dataSize = (
unsigned int)strtol(size_char, NULL, 16);
156 SerialUSB.println(dataSize);
164 SerialUSB.print(F(
"reading address: "));
165 SerialUSB.println(address, HEX);
167 eprom_read_write(
false);
168 for (i = 0; i < dataSize ; ++i) {
169 SerialUSB.print(
data[i], HEX);
170 SerialUSB.print(F(
" "));
177 SerialUSB.print(F(
"writing at address: "));
178 SerialUSB.print(address, HEX);
179 SerialUSB.print(F(
", len: "));
180 SerialUSB.println(address, dataSize);
181 for (i = 0; i < dataSize ; ++i) {
182 SerialUSB.print(
data[i], HEX);
183 SerialUSB.print(F(
" "));
185 eprom_read_write(
true);
190 SerialUSB.println(F(
"Memory test: writing and verifying the whole memory"));
201 if (SerialUSB.available() > 0) {
202 char inChar = SerialUSB.read();
203 SerialUSB.print(inChar);