Byte Order of EEPROM variables

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Freaks,

 

Seems I've learnt the hard way yet again...

I have been using ICC for megas but I've switched over to AtmelStudio (6.1|2) to make use of the xmega devices.  Seems the order the compilers stuffs variables into EEPROM is reversed. e.g.

 

In ICC I do the following:

#pragma data:eeprom
unsigned char EE_sBaud = 4;
unsigned char EE_sAddr = 1;
Gain_Val EE_sf = G8;
#pragma data:data

and i get the .eep file:

:03000000040103F5
:00000001FF

Now in AtmelStudio I do the following:

unsigned char EEMEM EE_sBaud = 4;
unsigned char EEMEM EE_sAddr = 1;
Gain_Val EEMEM EE_sf = G8;

with the corresponding .eep file contents:

:03000000030104F5
:00000001FF

The data bytes 04,01,03 (G8 = 03) have been put into EEPROM in the same order they appear in the file for ICC but in the reverse order for GCC.

Is this just the way things are normally for GCC? Is there a setting in Atmel Studio to force the order?

 

Cheers,

Steve.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

maybe this sheds some light (though it's rather old)

 

https://www.avrfreaks.net/forum/eeprom-data-order

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow. Sure does. Bummer. At least there's a work around.

Thanks for finding that.

 

Cheers,

Steve (Now embarrassed I didn't search. blush)

 

(And even more embarrassed I replyed to the wrong thread and resurrected a zombie! blushblush)

Didn't appear I could delete it strait away.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Address order is never guaranteed, not even for ICC.  One day the compiler maker may change it.  In fact, that has happened with the GCC toolchain.  By the way, it's the linker which is most directly responsible, not the compiler.

 

If order is important to you, use structs.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]