Q: Using avr/eeprom.h routines

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

Hello,

I am using AVR-GCC on an ATmega16, and want to do EEPROM accesses using the routines in the GCC libraries (referenced in #include avr/eeprom.h).

I have 2 questions which I didn't see answered in the docs:

1) The include file defines eeprom_read_byte as:

uint8_t eeprom_read_byte ( uint8_t * addr )

Does this mean I need to cast all of my eeprom addresses (which run from 0x00 to 0x1FF) to a pointer type? In the past they have just been uint8_t, not uint8_t *. Does this function want addresses from (uint8_t *)0x00 to (uint8_t *)0x1FF?

2) The include file defines eeprom_read_word as:

uint16_t eeprom_read_byte ( uint16_t * addr )

Are the address ranges for this function the same as for the byte read function, even though the type is uint16_t *? In other words, is the word data at (uint16_t *)0x13 the same as the 2 byte data at (uint8_t *)0x13 and (uint8_t *)0x14, or is the uint16_t * address multiplied by 2 (like word vs byte addressing of data) ?

Thanks!!

-- Steven

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

You have (at least) 2 choices:
- use absolute hardcoded addresses like 0x0, 0x2A and cast them to pointer (like in your post)
- use variables placed in EEPROm and refer to them during reading/writing eg.:
const uint8_t EE_pll_rampbmp __attribute__ ((section (".eeprom"))) = 10;
pll_rampbmp = eeprom_read_byte((uint8_t*)&EE_pll_rampbmp);

For the word reading there is no word aligment performed, passed address is used directly. It is up to you to pass a correct address.

BTW> in the incoming avr-libc release read fuctions will expect pointer to const, eg.
uint8_t eeprom_read_byte (const uint8_t *addr);

BTW2> remember do not use cell at address 0.

Regards,

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

Thanks for the info!
But I am confused about the comment:
"remember do not use cell at address 0."

Why wouldn't I use address 0? I didn't see anything in the data sheet about that.

Thanks,
Steven

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

EEPROM at address 0 is the same like other locations but:
My EEPROM location 0 is being destroyed. Why?

Regards,