Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Trying to understand my mistake... with pointers

Trying to understand my mistake... with pointers

Scheduled Pinned Locked Moved C / C++ / MFC
helpperformanceannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blubbo
    wrote on last edited by
    #1

    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!

    J L 2 Replies Last reply
    0
    • B Blubbo

      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!

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      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);

      1 Reply Last reply
      0
      • B Blubbo

        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!

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups