|
From: | E. Weddington |
Subject: | Re: [avr-gcc-list] read write eeprom WINAVR20050214 |
Date: | Fri, 18 Feb 2005 09:53:50 -0700 |
User-agent: | Mozilla Thunderbird 0.7.3 (Windows/20040803) |
Eivind Sivertsen wrote:
The address is an address to an 8 bit variable (which is 16 bits on AVR), nota 8 bit address. Basic C pointer stuff.---------------------------------------------- Oh yes, you are right. silly me! --Royce.- But the value to write is a uint16_t ...? Look: void eeprom_write_word (uint16_t *addr, uint16_t val)
Hi Eivind, The functions in question are these: uint8_t eeprom_read_byte (const uint8_t *addr) uint16_t eeprom_read_word (const uint16_t *addr) void eeprom_write_byte (uint8_t *addr, uint8_t val) void eeprom_write_word (uint16_t *addr, uint16_t val)The question had to do with eeprom_read_byte(). There are a lot of people who seem to "freak out" when they see that "uint8_t" in the parameter listing, and they think: "Oh, no! I can only write to the first 256 bytes in eeprom!"
But they don't look carefully enough to see that addr is a *pointer to an uint8_t*, and realize that a *pointer* is 16 bits. The pointer is pointing to a byte value, but the pointer itself can address up to 64K worth of memory.
This is a typical C language newbie question. And we should probably put this in the avr-libc FAQ or something.....
Eric
[Prev in Thread] | Current Thread | [Next in Thread] |