EmbeddedRelated.com
Forums

AVR (AT90S2313) EEPROM

Started by Tony Smith January 24, 2004
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.

Any docs or examples handy?

Thanks


On Sat, 24 Jan 2004 18:10:21 -0500, "Tony Smith" <z28.man@sympatico.ca>
wrote:

>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. > >Any docs or examples handy?
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. -- Rich Webb Norfolk, VA
Tony Smith wrote:
> > 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. > > Any docs or examples handy? > > Thanks
You didn't say if you are working in assembler or C or what. In C you might do it like this... int clr_lock_block() { int status; volatile int *addr; addr = (volatile int *)BASE_FLASH; *addr = FLASH_CMD_CLEAR_STATUS; *addr = 0x60; /* Clear block lock setup cmd */ *addr = 0xd0; /* Clear Block lock Confirm */ /* 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.
Tony Smith wrote:
> 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. > > Any docs or examples handy?
Most AVR programmers are able to write a piece of data into EEPROM. My favourite, avrdude, uses memory type eeprom for EEPROM: avrdude -p 2313 -c stk200 -e -U eeprom:w:myfile.eep The procedure to generate the EEPROM file depends on the toolset you're using. With the GNU toolset: - declare the EEPROM data into an own section, e.g. static const char my_string[] __attribute__ ((section(".eeprom"))) = "This data will be loaded into EEPROM"; - from the linked ELF file, make flash image: avr-objcopy -O srec myfile.elf myfile.rom - from the linked ELF file, make EEPROM image: avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \ -O srec myfile.elf myfile.eep 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. HTH Tauno Voipio tauno voipio @ iki fi
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. ?


On Sun, 25 Jan 2004 21:11:14 -0500, "Tony Smith" <z28.man@sympatico.ca>
wrote:

>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. ?
Load it via an Intel Hex format file. -- Rich Webb Norfolk, VA
Tony Smith wrote:
> 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.*) eeprom(rw!x) : ORIGIN = 0x810000, LENGTH = 128 in the standard script to eeprom(rw!x) : ORIGIN = 0x810001, LENGTH = 127 or (for 35) to eeprom(rw!x) : ORIGIN = 0x810000+35, LENGTH = 128-35 HTH Tauno Voipio tauno voipio @ iki fi