define variable at specified eeprom address

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

Hi all.
I've searched in the forum and google, but without success. Maybe I don't use the correct word.. Anyway, Is possible to define a variable in a specified location?
I want to store my variable
const char X EEMEM = 0x00;
at the end of eeprom.. How can I do it?

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

Hi,
Not exactly what you are asking, but you can use

uint8_t evar = 8;

//write evar to adr 900
eeprom_write_byte ((uint8_t *)(900), evar);
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, I know how to write in eeprom at run time, but what I want is something else..
Thanks however..

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

use a #define to define the adress and then use that define to write the data to the defined adress....

note that differetn chips have different eeprom sizes.

check a divise header file to see if something like eeprom-end is specified in there. then you can use that as your adress definition...

regards

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

Try to search for similar topics – how to store variable at particular SRAM address.
Briefly, you need to define additional section, store your variable at that section, and give section address as parameter to the linker.

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

If you want to initialize eeprom at a specific address in the source code, you can define your own section with that as a starting address:

char foo[] __attribute__ ((section (”.foosection″)))= 0x42;

and pass the eeprom address to the linker:

$ avr-gcc ... -Wl,--section-start=.foosection=0x81nnnn

Alternately you could allocate a dummy variable that starts at the beginning of eeprom and offsets your variable to the desired location:

char bar[nnnn] EEMEM;
char foo EEMEM = 0x42;