Hi,
Where is does my H went in the readChar function?
Start your code here #include <EEPROM.h>
//#include <Arduino.h> #define EEPROM_SIZE 40
void writeChar(uint8_t ad, const char *ch)
{
printf("%d\n", ad);
printf("%d: %c\n", ad++, *ch);
EEPROM.write(ad, *ch);
EEPROM.commit();
while (*ch++ != '\0') {
EEPROM.write(ad, *ch);
EEPROM.commit();
printf("%d: %c\n", ad++, *ch);
}
}
void readChar(uint8_t ad)
{
uint8_t ch = '\0'; ch = EEPROM.read(ad++);
Serial.printf("%c", ch);
while (ch != '\0') {
Serial.printf("%c", ch);
ch = EEPROM.read(ad++);//ch address is always the same
}
}
void setup() {
Serial.begin (115200);
EEPROM.begin(EEPROM_SIZE);
const char *hel = "Hello once in a while.";
writeChar(7, hel);
Serial.println("\n----------------------------");
readChar(7); Serial.println("\n----------------");
Serial.println(EEPROM.read(0));
Serial.println(EEPROM.read(1));
Serial.println(EEPROM.read(2));
Serial.println(EEPROM.read(3));
Serial.println(EEPROM.read(4));
Serial.println("\n----------------");
Serial.println((char)EEPROM.read(7));
Serial.println((char)EEPROM.read(8)); //EEPROM.write(0,'H');//Reset memory value
//EEPROM.write(1,'e');
//EEPROM.write(2,'l');
//EEPROM.write(3,'l');
//EEPROM.write(4,'o');
//EEPROM.commit();
}
void loop() { }
Start your code hereentry 0x400806ac
7
7: H
8: e
9: l
10: l
11: o
12:
13: o
14: n
15: c
16: e
17:
18: i
19: n
20:
21: a
22:
23: w
24: h
25: i
26: l
27: e
28: .
29: --------- readChar ------------------- ⸮⸮ello once in a while. ---------------- 72 101 108 108 111 ---------------- ⸮ e
Regards
JPDaviua
Hi.
I don’t know why it doesn’t work. But replacing your readChar function with this, solves the problem:
void readChar(uint8_t ad) {
uint8_t ch = '\0';
ch = EEPROM.read(ad);
Serial.print((char)ch);
while (ch != '\0') {
ad++;
ch = EEPROM.read(ad);//ch address is always the same
Serial.print((char)ch);
}
}
Regards,
Sara
Thanks.
#include
#define EEPROM_SIZE 55
void writeChar(int16_t ad, const char *ch)
{
EEPROM.write(ad++, *ch);
EEPROM.commit();
printf("%d: %c\n", ad, *ch);
while (*ch++ != '\0') {
printf("%d: %c\n", ad, *ch);
EEPROM.write(ad++, *ch);
EEPROM.commit();
}
}
void readChar(int16_t ad)
{
uint8_t ch = '\0';
ch = EEPROM.read(ad++);
while (ch != '\0') {
Serial.printf("%c", ch);
ch = EEPROM.read(ad++);//ch address is always the same
}
}
void setup() {
Serial.begin (115200);
EEPROM.begin(EEPROM_SIZE);
const char *hel = "Hello once in a while.";
//int16_t lnth = strlen(hel);
uint8_t from = 6;
writeChar(from, hel);
Serial.println("\n----------------------------");
readChar(from);
Serial.println("\n----------------");
Serial.println((char)EEPROM.read(6));
Serial.println((char)EEPROM.read(7));
Serial.println((char)EEPROM.read(8));
}
void loop() {
}