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 CCS Technical Support

saving struct values in eeprom

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



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

saving struct values in eeprom
PostPosted: Tue Aug 07, 2007 1:16 pm     Reply with quote

Hi all. Smile

I need to backup values in a complex struct to/from eeprom. The easiest way, I think, would be to access the individual bytes of the struct like the elements of an array. The struct uses a total of 43 bytes, consisting of various int8s, int32s, and 32-bit floats.

Are the bytes of a struct kept contiguous by the compiler?

Is there an easy way to do this in c?

Thanks for your help and/or suggestions.

Sincerely,
Jim
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 07, 2007 4:41 pm     Reply with quote

See this post, regarding a union between an array and other structure
elements.
http://www.ccsinfo.com/forum/viewtopic.php?t=18729

That method depends upon CCS packing all structure elements on a
1-byte boundary, with no padding. I believe they do that.

The reason for the delay in answering was that I kept searching the
archives for an old post, where I state that. I couldn't find it, so I
just finally re-stated it above.
soundscu



Joined: 29 Jun 2007
Posts: 62
Location: Raleigh, NC

View user's profile Send private message Visit poster's website

Thanks!
PostPosted: Tue Aug 07, 2007 7:50 pm     Reply with quote

Your suggestion has led to a working routine! The syntax for using a struct in a union isn't quite what I thought it was.

Incidentally, my application is a touch more complicated because I use a 7-element array of the struct I defined. Evenso, success!

Thanks very much.

But now I have a new problem... see my new subject "write_eeprom not working with PIC18F6722". :(
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Wed Aug 08, 2007 12:21 am     Reply with quote

Personally i have similar question. Is there any way to declare a data structure directly in EEPROM using #rom directive? Something like:
Code:
typedef struct
{
  int8 x;
  int16 y;
  ZaOtherThing t;
  char z;
}ZaThing;
and later on:
Code:
#rom ZaThing 0xF00008 = {4,450,{45, 22}, 'a'};
without declaring byte by byte?
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