View previous topic :: View next topic |
Author |
Message |
paul_dean
Joined: 18 Jan 2013 Posts: 6
|
Reading/Writing string to external EEPROM |
Posted: Thu Jan 24, 2013 6:53 am |
|
|
I am reading a 24 character number from the serial port. I would like to store this number to an external EEPROM. I do know how to read and write 256 byte numbers to eeprom, however I do not know how to store this 24 character array. I am using 24lc512 external eeprom. Any help? ideas? thanks in advance. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jan 24, 2013 1:27 pm |
|
|
See this thread for an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=35685
This example is for a string. A string is an array of ASCII characters
with a final terminator byte of 0x00. Make sure that your data is
actually a string, and not just a series of random numbers. |
|
|
paul_dean
Joined: 18 Jan 2013 Posts: 6
|
|
Posted: Fri Jan 25, 2013 12:30 am |
|
|
Thanks for that link. However the number I am reading in is just an array of numbers, how do I create a string? |
|
|
paul_dean
Joined: 18 Jan 2013 Posts: 6
|
|
Posted: Fri Jan 25, 2013 12:38 am |
|
|
In that case hello world is a string created by the programmer, but in my case I am reading in a random array of numbers. Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Jan 25, 2013 2:53 am |
|
|
Seriously, a string _is_ just numbers. They happen to be ASCII values, but everything else is the same. You can initialise an array (or an area in ROM), with:
{0x30,0x31,0x32,0x33,0}
or with:
{"0123"}
and in both cases, the numbers stored are exactly the same.
Once you realise that strings are numbers, the relationship of 'string code' to 'number code', becomes easier to understand.
Best Wishes |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Fri Jan 25, 2013 3:11 am |
|
|
I like to build structs with all my pertinent config info built inside them.
Then no matter what the struct has in it, it can still be written/read byte by byte.
Code: |
struct {
unsigned int8 val1;
signed int16 val2;
unsigned char string[20];
float fancyNumber;
} config;
|
write out the same way as reading in and it all matches up.
-Ben
p.s. Also, if you know the size of your EEPROM, as/if you add things to the config, you can always test the sizeof(config) to see if you have enough space on your EEPROM to fit all of it. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
paul_dean
Joined: 18 Jan 2013 Posts: 6
|
|
Posted: Fri Jan 25, 2013 3:24 am |
|
|
Ok thanks alot guys. |
|
|
|