16bit values into 8bit eeprom

C

cerr

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!
 
I

Ike Naar

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top