Hi all,
Firstly, I am relatively new at this and especially new (read, never used) when it comes to pointers which I believe I may need to accomplish this task.
I'm planning to use a 16x2 LCD display to display over 40 different messages at one time or another and I'd like to get these message in EEPROM using the eeprom_write_block and read from the eeprom using eeprom_read_block from the avr/eeprom.h library
I've found this discussion that references EEMEM as an array in EEPROM.
Read/Write to EEPROM using AVR/EEPROM.h (SOLVED) - Programming Questions - Arduino Forum, as such, I have created arrays for the text messages and equivalent arrays in EEPROM using the EEMEM attribute (which I also really don't understand). The arrays in EEPROM have no specific location to them as far as I can see when using the EEMEM array. I'm assuming the compiler decides where to start each array.
If I write to eeprom using the eeprom_write_block per the attached code (it's incomplete because I don't know how to complete this code), what is the best method of locating the beginning of the string in EEPROM AFTER it's written?
#include <avr/eeprom.h>
#define NUM_MAX 17 // LCD String length (incl \0)
#define eeprom_busy_wait;
/****** LCD EEPROM Arrays *******/
char EEMEM lcdMsgLoc1[NUM_MAX];
char EEMEM lcdMsgLoc2[NUM_MAX];
char EEMEM lcdMsgLoc3[NUM_MAX];
char EEMEM lcdMsgLoc4[NUM_MAX];
/**** Known EEPROM Locations ****/
int msgPtr1 = 920; // Known EEPROM location for lcdMsgLoc1 address
int msgPtr2 = 922; // Known EEPROM location for lcdMsgLoc2 address
int msgPtr3 = 924; // Known EEPROM location for lcdMsgLoc3 address
int msgPtr4 = 926; // Known EEPROM location for lcdMsgLoc4 address
/********** STRINGS *************/
char lcdMsg1[NUM_MAX] = "Message Number 1";
char lcdMsg2[NUM_MAX] = "Message Number 2";
char lcdMsg3[NUM_MAX] = "Message Number 3";
char lcdMsg4[NUM_MAX] = "Message Number 4";
void setup(){
// LCD Text messages
eeprom_write_block (lcdMsg1, lcdMsgLoc1, NUM_MAX);
char *locAdd; // define a pointer
locAdd = &lcdMsgLoc1[0]; // pointer points to address of lcdMsgLoc1[0]
// write the address into another EEPROM location - ????
// when ready to read string, read block starting at address written in EEPROM - ???
}
void loop()
{}
FWIW, my guess is to define a pointer to the address of the 0 element of the EEMEM array and write that address into a known location in EEPROM - but I have tried for a few days to figure this out to no avail. I'm not looking for someone to code this for me but rather tell me if I'm on the right track or not. I can go back to reading the C Programming Book by Kernighan and Ritchie if needed but this book is proving to be of little help for this.
Thanks in advance