View previous topic :: View next topic |
Author |
Message |
janet
Joined: 17 Feb 2004 Posts: 23
|
how to get a varible from external - eeprom |
Posted: Wed Mar 17, 2004 3:05 am |
|
|
Hi,
BYTE string1[] = "hello world";
printf("%s", string1);
This is valid if i use the internal eeprom (18F452).
What if i want to store the string to i2c external eeprom (24LC256)?
do I have to supply every BYTE with a eeprom address?
It will be tedious if i have to specify address for each byte in the string.
When i want to retrieve the string, do i have to repeat the same thing? |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
|
janet_smith2000 Guest
|
|
Posted: Wed Mar 17, 2004 7:33 am |
|
|
actually i can read and write the external eeprom
the problem i face is that
I CANNT get a value by specifying the varible name. instead, i have to supply memory address for that.
for example, i cannt read a value by simply writing
printf("%u", variable_name");
instead, i have to KNOW the address of the content in ADVANCE!.
What is the conventional way of retrieving data from eeprom? |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
eeprom access |
Posted: Wed Mar 17, 2004 8:02 am |
|
|
EEPROM is handy, but not easily accessed in that it does not appear as straight memory. I don't think there is a 'convential' way to read from EEPROM; you need to come up with some trick that will work for you and make your code read and work cleanly.
Fo example if you have a bunch of constant strings in internal EEPROM you could access them via a function call:
Code: | void GetEEString(char * ramstr, int8 EEstart, int8 EElen)
{
while( EElen-- > 0 )
*ramstr++ = read_eeprom(EEStart++);
} |
I haven't tested that , but you should get the general idea.
This would copy a particular string in EEPROM into 'ramstr'. And yes, you will need to know the start location and length of each string beforehand. I would define constants for each. If you had a variety of variables you could define a structure and have routines that save and retrieve the structure.
Basically you need to write something to encapsulate the EEPROM access. A 'go between' to make the EEPROM look more like a normal memory. Think of the EEPROM as disk drive - you need to provide the driver and file struture to access it.
- SteveS |
|
|
|