avr/eeprom.h addresses

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

Hello my fellow AVR-nauts. I'm looking into using the avr/eeprom.h include to manage my EEPROM reads/writes, but I'm confused about the addresses. eeprom_read_byte and eeprom_write_byte only accept 8-bit addresses, so you can only access the lower 256 bytes of EEPROM. This is fine for small projects, but an atmega64, for example, has 2K bytes of EEPROM. If I'm addressing outside of an 8-bit range, it looks like I have to use eeprom_read_word or eeprom_read_dword, but then I can't just read a single byte anymore. Maybe it's better (in the design/readability sense) to keep variables in the .eeprom section with the EEMEM attribute when you start using a large amount of non-volatile storage, but I'm still curious how you could access single bytes at large addresses with the built-in functions. In previous projects, I've coded the EEPROM handling myself, but I would like to try the nice included header for a change. Sorry if this has been answered before... I wasn't able to find it in the search.

- Allen Jordan

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

Quote:

only accept 8-bit addresses

Not true - they accept POINTERs to 8 bit quantities. AVR pointers are 16bit so can address 65536 bytes. If you had 2K of EEPROM you could easily:

uint8_t e_data[2048] EEMEM = { 1,2,3,4,5,...};

val = eeprom_read_byte(&e_data[541]);

to read the 542'nd element of the array.

The _byte and _word in the eeprom_() routines is dictating the size of the object read/written, not the size of the pointer.

Cliff

When/if Atmel make an AVR with >64K EEPROM *then* there could be problems - but these are already being faced with RAM and code flash pointers anyway

Last Edited: Mon. Jun 15, 2009 - 07:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bobasaurus wrote:
eeprom_read_byte and eeprom_write_byte only accept 8-bit addresses
No, they don't.

Stealing Proteus doesn't make you an engineer.

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

God I'm retarded sometimes. Thanks for pointing that out to me. I forgot that pointer sizes differ from (are independent of, I guess) the type they point to.