View previous topic :: View next topic |
Author |
Message |
soundscu
Joined: 29 Jun 2007 Posts: 62 Location: Raleigh, NC
|
saving struct values in eeprom |
Posted: Tue Aug 07, 2007 1:16 pm |
|
|
Hi all.
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
|
|
Posted: Tue Aug 07, 2007 4:41 pm |
|
|
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
|
Thanks! |
Posted: Tue Aug 07, 2007 7:50 pm |
|
|
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
|
|
Posted: Wed Aug 08, 2007 12:21 am |
|
|
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? |
|
|
|