I have been doing a lot of searching and reading, but haven't found what I need. I would like to store values at a specific EEPROM address and to have an initial value. I know how to declare a varible that will compile to be programmed in the EEPROM starting at address 0.... But I want to specify the address where it will be programmed.
Well, the STK500 plugin for AVR Studio can burn a specified hex file into the EEPROM. If you just need a single byte then the "oscillator calibration byte" facility will let you write an arbitrary value to any EEPROM address and I suppose you could extend that with multiple writes.
/* Wait for SR.7 */ while (((*addr) & 0x80)==0); status = *addr & (0x2+0x8+0x20); /* mask off error bits from flash */ *addr = 0xff; /* Put flash in read mode */ return(status); }
This is a subroutine that was used to control an external flash memory. The part you are interested in is the way addr was used. It was declared to be a pointer to an int and initialized to the value of the define constant "BASE_FLASH". Then to access the location it points to you use the * symbol in front of it as shown in the next several lines.
You need to read up on the procedure for programming your EEPROM and work according to that using pointers to set the fixed address.
The example generates image files in the Motorola S-record (srec) format. Any other supported format may be substituted after the
-O switch (e.g. ihex, binary).
Please note that you can have data to the EEPROM in several modules, but the addresses will then be allocated by the linker when combining the modules into the linked file.
The EEPROM data has to be accessed via the I/O ports. There are functions for it in the GNU AVR library, see manual.
In some AVR's there is an errata about corruption of EEPROM location zero at power cycling. I'd avoid saving any valuable data in the first location.
Thanks for the help so far guys, however I did have this much working fine already. I know how to program the eeprom and make variables that will be stored in EEPROM as well as read and write. But in some cases I want to specify the address where data will be stored so that when I program it, my code can read out a value at the same location every time.
For example as Tauno has shown sometimes you want to avoid address zero, so how would I make the string "This data will be loaded into EEPROM" start from address 1? Or even 35. ?
The tool to locate a piece of data into a pre-determined address is the linker script. The units controllable with the script are object file sections. You may modify the standard linker script (found at the AVR library installation directory) to suit your requirements and specify it to be used instead of the standard one with a command line switch (-T for ld, or -Wl,-T for GCC).
To the direct question: change the line (in avr23xx.*)
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.