16bit values into 8bit eeprom

Discussion in 'C Programming' started by cerr, Feb 17, 2011.

  1. cerr

    cerr Guest

    Hi There,

    I'm having troubles storing an array of 16 16bit values into an 8bit
    eeprom and read it back.
    I read all weird values... :(. My functions look like this:
    void WriteToEEPROM(eevalues* data)
    {
    int8 i=0;
    for (i=0; i<VARNUM; i++){
    write_eeprom((i*2),*((int8*)&(data->value)));
    write_eeprom((i*2)+1,*((int8*)&(data->value) + 1));
    }
    }
    //------------------------------------------------------------------------------

    void ReadFromEEPROM(eevalues* data)
    {
    int8 i;

    for (i = 0; i<VARNUM; i++)
    *((int8*)&(data->value)) = read_eeprom((i*2));
    *((int8*)&(data->value)+1) = read_eeprom((i*2)+1);
    }

    May anyone be able to help me and point me into the right direction?
    Thank you!
     
    cerr, Feb 17, 2011
    #1
    1. Advertising

  2. cerr

    Ike Naar Guest

    On 2011-02-17, cerr <> wrote:
    > I'm having troubles storing an array of 16 16bit values into an 8bit
    > eeprom and read it back.
    > I read all weird values... :(. My functions look like this:
    > void WriteToEEPROM(eevalues* data)
    > {
    > int8 i=0;
    > for (i=0; i<VARNUM; i++){
    > write_eeprom((i*2),*((int8*)&(data->value)));
    > write_eeprom((i*2)+1,*((int8*)&(data->value) + 1));
    > }
    > }
    >
    > void ReadFromEEPROM(eevalues* data)
    > {
    > int8 i;
    >
    > for (i = 0; i<VARNUM; i++)
    > *((int8*)&(data->value)) = read_eeprom((i*2));
    > *((int8*)&(data->value)+1) = read_eeprom((i*2)+1);
    > }


    You're missing a pair of curly braces around the body of the
    for loop in ReadFromEEPROM.
     
    Ike Naar, Feb 17, 2011
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramon

    Accessing PIC's EEPROM

    Ramon, May 4, 2004, in forum: C Programming
    Replies:
    3
    Views:
    1,428
    Mark A. Odell
    May 5, 2004
  2. humble
    Replies:
    0
    Views:
    891
    humble
    Oct 28, 2006
  3. george jetson

    Embeddable Pcode compiler/interpreter Serial EEPROM

    george jetson, Jul 7, 2004, in forum: C Programming
    Replies:
    1
    Views:
    460
    Grumble
    Jul 9, 2004
  4. Daniele M.
    Replies:
    2
    Views:
    392
    Daniele M.
    Mar 6, 2008
  5. cerr

    store 16bit values in 8bit eeprom

    cerr, Feb 17, 2011, in forum: C Programming
    Replies:
    2
    Views:
    1,026
    BartC
    Feb 18, 2011
Loading...

Share This Page