Since I have managed to use M42C02 via I2C. Now I need to know how to store int (2 bytes), long int values (4 bytes) and floating point number (4 bytes) in EEPROM chip. But I don't have any clue how to do it. Your help would be appreicated
Suppose the floating point result is obtained from a sensor of 16-bit resolution, we may use a union to store the raw sensor result. By using a union, we store the floating point (4-bytes) in the union. The advantage is that, we save a lot for the eeprom by storing only the raw data. Consider this:
Code:
typedef union
{
unsigned int i; //raw data obtained from the sensor
float f;
} value;
void main()
{
value temp_val;
//store temp_val.i in eeprom for 2 bytes here to store the raw data
eeprom_store2bytes(address,temp_val.i);
//read back the value and store it back in temp_val.i
eeprom_read2bytes(address,&temp_val.i);
}
However, if there is a need to store the floating point result without considering what sensor raw data is nor using union, it is possible to locate the address of the floating point declared and store that 4-bytes representation by:
typedef union
{
unsigned int i;
float f;
} value;
void main()
{
value temp_val;
//store temp_val.i in eeprom for 4 bytes here
eeprom_store4bytes(address,temp_val.i);
//read back the value and store it back in temp_val.i
eeprom_read4bytes(address,&temp_val.i);
//floating point result here, may be printed to LCD
temp_val.f=(float)temp_val.i;
}