Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to write float to eeprom and read float from eeprom

Status
Not open for further replies.

arash rezaee

Member level 5
Joined
Sep 10, 2009
Messages
87
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,952
how to read from eeprom and convert it to float

Hi every one
I am using ATXmega128A1 and the compiler is codevision. Does any one know how to convert 4byte to fload which I stored them into eeprom and I don`t know how can I convert them to float again.
this is the code i used to convert float to byte:
union
{
float KX1;
unsigned char bytevalue[4];
}variable;
Please help me.
Regards
Arash
 
Last edited:

Thanks. I used union and sounds like it works. but I don`t know how to convert 4byte to float using union. Do you know?
 

You don't convert anything to a union, it's a shared memory space that can be referred to in different ways. Save your float to a union consisting of 4 bytes then save the bytes one at a time to EEPROM. To read from the EEPROM, save bytes in consecutive byte sized locations in the union and read it as a float type.

Brian.
 

You don't need to make any conversion, just use

Code:
eeprom float my_float;  // variable stored in eeprom
 

Do you want to represent something like 0xABCD (4 bytes) as float 43981.000?
 

ok, thanks. I will check it and get back to you.

- - - Updated - - -

You don't need to make any conversion, just use

Code:
eeprom float my_float;  // variable stored in eeprom

you mean in codevision??? But I wrote my own code to write and read from eeprom. Is it really simple? what about If I what to read from eeprom( I mean for floats)? I must mention that I have 10 float number that I need to store them to eeprom.
thanks

- - - Updated - - -


yes. I have 10 coefficients and they are like 27.85451 and so on. so I want to store them and later read them and use them.
Cheers
 

codevision simplifies that process for you.

you use
Code:
eeprom variable_type variable_name= initial_value;

To read a float variable just use the name it has


Code:
eeprom float my_eeprom_float=0.0;  // variable stored in eeprom initializes to 0
float my_ram_float;  // RAM variable

my_ram_float=my_eeprom_float;   // copy eeprom to ram

my_eeprom_float=my_ram_float;   // copy ram to eeprom
 

codevision simplifies that process for you.

you use
Code:
eeprom variable_type variable_name= initial_value;

To read a float variable just use the name it has


Code:
eeprom float my_eeprom_float=0.0;  // variable stored in eeprom initializes to 0
float my_ram_float;  // RAM variable

my_ram_float=my_eeprom_float;   // copy eeprom to ram

my_eeprom_float=my_ram_float;   // copy ram to eeprom

That a lot. one more question: Where does it store in eeprom? I mean Does it store it in first page and so on or it is random? I have more valiables which I need to store in eeprom but they are char and I wrote my own code to store them in specific address of eeprom which I address it. So does this type of storing interfere with other datas?
 

This way you have no control of the exact position but I think there is another way to specify the exact address.
Check the manual.

You can also use the same way for all eeprom variables

Code:
eeprom char my_char;
eeprom integer my_integer;
eeprom char my_array[10];
....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top