EmbeddedRelated.com
Forums

floating point no in eeprom

Started by Anish May 29, 2003
Hi
I want to store a floating point number to a location in eeprom.
This is my code

float resulta;
unsigned char *introm_var0 = (unsigned char *) 0xD40;
resulta = 0.56;
*introm_var0 = resulta;

The problem is that it stores 00 in that location.

Do i have to use some logic to convert my floating point number to
hex and then store it. or is there any other method to do it.

Anish



Anish,

You are an area where the names somewhat misleading due to accidents of
computer history.

You need to erase the EEPROM sector and re-program it. It is not nearly as
simple as doing a store into RAM.

If you are lucky there is a C library function to do this, but you will
need to tell the C library function the clock speed you are using.

Many compilers do not have this function. In this case you must write on
yourself or modify some example code.

The section of your processor's documentation on EEPROM will likely give a
flow chart for programming EEPROM.

If you look at the Motorola Semiconductor web site, you can find the
documentation and probably an "Application Note" with some sample code.

You must be careful to match the EEPROM programming algorithm to the
processor. Motorola so far has had 3 different designs of EEPROM control
in HC(S)-12 processors.

Hope this helps. If you find it unclear, please ask some more questions.

Further Notes below.

Steve

At 04:08 PM 5/29/2003, you wrote:
>Hi
>I want to store a floating point number to a location in eeprom.
>This is my code
>
>float resulta;
>unsigned char *introm_var0 = (unsigned char *) 0xD40;
>resulta = 0.56;
>*introm_var0 = resulta;
>
>The problem is that it stores 00 in that location.

The full name of EEPROM is "Electrically Erasable Programmable Read Only
Memory". The effect you are seeing is the "Read Only" feature. A better
name is "Non Volatile Memory" and some of the Motorola documentation is
using that term.

Historically ROM (true "Read Only Memory") was soon replaced with various
kinds of "ROM" that could be written. These were called "Programmable".

The word "Programmable" suggests the truth that changing the contents
requires a multi-step program of some kind, not a just a simple write.

>Do i have to use some logic to convert my floating point number to
>hex and then store it. or is there any other method to do it.

The hex conversion is only required by the EEPROM programmers that work
from an external input, such as a file in your PC or a file sent to the
HC-12 through the SCI. These files are eventually read by a program in the
HC-12 which converts the hex into binary before programming the data into
flash or EEPROM.

The data stored in HC-12 memory is all binary. Floating point numbers
stored in RAM, EEPROM and flash all have the same binary values.

>Anish >
><http://ashnin.com/clk/muryutaitakenattogyo?YH313099&yhad95056>1fdd15f.jpg" target="_blank" rel="nofollow">http://rd.yahoo.com/M$4522.3313099.4604523.1512248/D=egroupweb/S06554205:HM/A95056/R=0/*http://ashnin.com/clk/muryutaitakenattogyo?YH313099&yhad95056>1fdd15f.jpg
>1fdd1cd.jpg
>
>--------------------
>>http://www.motorola.com/mcu >">http://docs.yahoo.com/info/terms/>Yahoo! Terms of Service.


*************************************************************************
Steve Russell mailto:
Senior Software Design Engineer http://www.nohau.com
Nohau Corporation phone: (408)866-1820
51 East Campbell Avenue fax: (408)378-7869
Campbell, CA 95008
*************************************************************************



You need to treat the float as a sequence of characters and write them
sequentially
For example:
*src = (unsigned char *) &resulta;
for (i = 0; i < sizeof(float); i++)
{
*(introm_var0++) = *(src++);
}
this all assumes you're using a compiler that provides proper timing to
write to EEPROM locations.

At 11:08 PM 5/29/2003 +0000, you wrote:
>Hi
>I want to store a floating point number to a location in eeprom.
>This is my code
>
> float resulta;
> unsigned char *introm_var0 = (unsigned char *) 0xD40;
> resulta = 0.56;
> *introm_var0 = resulta;
>
>The problem is that it stores 00 in that location.
>
>Do i have to use some logic to convert my floating point number to
>hex and then store it. or is there any other method to do it.
>
>Anish >
>-------------------- >
>">http://docs.yahoo.com/info/terms/

--------------------
Jim Bacon
Software Engineer
Melles Griot Electro-Optics -- Longmont, Colorado

720-494-4938 x329