CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Reading/Writing string to external EEPROM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
paul_dean



Joined: 18 Jan 2013
Posts: 6

View user's profile Send private message

Reading/Writing string to external EEPROM
PostPosted: Thu Jan 24, 2013 6:53 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 24, 2013 1:27 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2013 12:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2013 12:38 am     Reply with quote

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: 19401

View user's profile Send private message

PostPosted: Fri Jan 25, 2013 2:53 am     Reply with quote

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: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Jan 25, 2013 3:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 25, 2013 3:24 am     Reply with quote

Ok thanks alot guys.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group