In a program for use with a micro, I have a variable of type float (real number) and wish to save it to EEPROM. I have a routine which writes a byte at a time to EEPROM at the location (address) I designate.
The problem comes in that I do not know how the variable (type float) is stored. I do know that a variable of type floats is a 32 bit value in the compiler I am using.
Is it as simple as writing each of the 4 bytes of the float (real), and later reading them back in? I feel I am missing something in this:
What I am imagining is something along these lines:
float ScaleFctr; // Real number
unsigned int i; // Start address in EEPROM where to save the real number
Write real to EEPROM:
I2CWrByte (EEPROM, i, st_ptr->ScaleFctr >> 24);
I2CWrByte (EEPROM, i+1, st_ptr->ScaleFctr >> 16);
I2CWrByte (EEPROM, i+2, st_ptr->ScaleFctr >> 8);
I2CWrByte (EEPROM, i+3, st_ptr->ScaleFctr & 0x00FF);
Read real from EEPROM:
I2CRdByte (EEPROM, i, &EEByteH);
I2CRdByte (EEPROM, i+1, &EEByteM);
I2CRdByte (EEPROM, i+2, &EEByteM2);
I2CRdByte (EEPROM, i+3, &EEByteL);
CalData.ScaleFctr = (EEByteH<<24) + (EEByteM<<16) + (EEByteM2<<8) + EEByteL;
Thanks .