Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   16bit values into 8bit eeprom (http://www.velocityreviews.com/forums/t743747-16bit-values-into-8bit-eeprom.html)

cerr 02-17-2011 06:31 PM

16bit values into 8bit eeprom
 
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[i]->value)));
write_eeprom((i*2)+1,*((int8*)&(data[i]->value) + 1));
}
}
//------------------------------------------------------------------------------

void ReadFromEEPROM(eevalues* data)
{
int8 i;

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

May anyone be able to help me and point me into the right direction?
Thank you!

Ike Naar 02-17-2011 11:50 PM

Re: 16bit values into 8bit eeprom
 
On 2011-02-17, cerr <ron.eggler@gmail.com> 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[i]->value)));
> write_eeprom((i*2)+1,*((int8*)&(data[i]->value) + 1));
> }
> }
>
> void ReadFromEEPROM(eevalues* data)
> {
> int8 i;
>
> for (i = 0; i<VARNUM; i++)
> *((int8*)&(data[i]->value)) = read_eeprom((i*2));
> *((int8*)&(data[i]->value)+1) = read_eeprom((i*2)+1);
> }


You're missing a pair of curly braces around the body of the
for loop in ReadFromEEPROM.


All times are GMT. The time now is 01:23 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.