Trying to understand my mistake... with pointers
-
I've got this the following code snippets... when compiling, I kept on getting error: implicit declaration of function. This "eeprom_memory_update_byte" came from avr/eeprom.h. What I am trying to update the atmel processor eeprom memory (not write, but to update) In commands.c (in a function):
bool Update_EEPROM_Memory_byte(byte val1, byte val2)
{
uint8_t eepromAddr = val1;
uint8_t eepromVal = val2;eeprom_memory_update_byte(eepromAddr, eepromVal);
return 1;
}In eeprom.h
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
In eeprom.c
bool eeprom_memory_update_byte(uint8_t eeprom_addr, uint8_t eepromValue)
{
eeprom_update_byte((uint8_t*) eeprom_addr, eepromValue);uint8\_t eepromVal = eeprom\_read\_byte(( uint8\_t \*) eeprom\_addr); if (eepromValue == eepromVal) return 1; else return 0;
}
please help!
-
I've got this the following code snippets... when compiling, I kept on getting error: implicit declaration of function. This "eeprom_memory_update_byte" came from avr/eeprom.h. What I am trying to update the atmel processor eeprom memory (not write, but to update) In commands.c (in a function):
bool Update_EEPROM_Memory_byte(byte val1, byte val2)
{
uint8_t eepromAddr = val1;
uint8_t eepromVal = val2;eeprom_memory_update_byte(eepromAddr, eepromVal);
return 1;
}In eeprom.h
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
In eeprom.c
bool eeprom_memory_update_byte(uint8_t eeprom_addr, uint8_t eepromValue)
{
eeprom_update_byte((uint8_t*) eeprom_addr, eepromValue);uint8\_t eepromVal = eeprom\_read\_byte(( uint8\_t \*) eeprom\_addr); if (eepromValue == eepromVal) return 1; else return 0;
}
please help!
The first parameter in eprom_update_byte() function declaration is different than what is the the implemntation. In the .h file it is a pointer to a uint8_t (uint8_t *__p), and in the implementation it is a copy of the object (uint8_t eeprom_addr) passed by value. I'm guessing, change the implementation line in the .c file. But that might cause you to call the function differently like, eeprom_memory_update_byte(&eepromAddr, eepromVal);
-
I've got this the following code snippets... when compiling, I kept on getting error: implicit declaration of function. This "eeprom_memory_update_byte" came from avr/eeprom.h. What I am trying to update the atmel processor eeprom memory (not write, but to update) In commands.c (in a function):
bool Update_EEPROM_Memory_byte(byte val1, byte val2)
{
uint8_t eepromAddr = val1;
uint8_t eepromVal = val2;eeprom_memory_update_byte(eepromAddr, eepromVal);
return 1;
}In eeprom.h
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
In eeprom.c
bool eeprom_memory_update_byte(uint8_t eeprom_addr, uint8_t eepromValue)
{
eeprom_update_byte((uint8_t*) eeprom_addr, eepromValue);uint8\_t eepromVal = eeprom\_read\_byte(( uint8\_t \*) eeprom\_addr); if (eepromValue == eepromVal) return 1; else return 0;
}
please help!
You haven't given us the implementation of this prototype function
void eeprom_update_byte (uint8_t *__p, uint8_t __value);
Implicit declaration error usually means you provided a prototype but no body code ... hence I am worried you haven't given me that functions code. I am assuming the EEPROM is flash and that code will do what we call the toggling test until it writes the byte to the flash. Warning if it is FLASH you usually also have to release protection registers by writing special commands to special addresses before you can write to the flash, did the original code also provide a function to release the protection on a sector per chance? However onto your code as it stands, you are passing in the address to write as a byte which gives you a range of 0-255 in memory see here
bool Update_EEPROM_Memory_byte(byte val1, byte val2) { // Val1 is a byte
uint8_t eepromAddr = val1; // <== Really a byte as the address you can only write to memory address 0--0xff
uint8_t eepromVal = val2;The original function they provided had a pointer to an byte (uint_8) which will be most likely be 32 bit ... see
void eeprom_update_byte (uint8_t *__p, uint8_t __value); // First parameter is a pointer see the "*"
I suspect you need your address to be a long ..... try
bool Update_EEPROM_Memory_byte(unsigned long val1, byte val2){
unsigned long eepromAddr = val1; // <== Now you can write to memory address 0-0xffffffff
uint8_t eepromVal = val2;Adjusted last function to take the long
bool eeprom_memory_update_byte(unsigned long eeprom_addr, uint8_t eepromValue)
{
eeprom_update_byte((uint8_t*) eeprom_addr, eepromValue);uint8\_t eepromVal = eeprom\_read\_byte(( uint8\_t \*) eeprom\_addr); if (eepromValue == eepromVal) return 1; else return 0;
}
The alternative to an unsigned long for the address is to keep it as a pointer (uint8_t*). That all means nothing if you have no code for the function eeprom_update_byte which isn't shown. Other housekeeping Update_EEPROM_Memory_byte should return the result of eeprom_memory_update_byte rather than a static 1 (TRUE) result.
In vino veritas