cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ Creator & Designer

Anonymous
Not applicable

Hi,

   

I have what will most likely be a very easy question for some to answer.  But,  not being a very good bit twiddler I need to ask this:

   

How do I manage variables of type float in relationship to storing and accessing them in EEPROM?  I have byte level access working properly so the basics have been covered. 

   

Code snippet:
//Storing the float (wpm is a float)  Store it in the Third Row
error = EEPROM_Write((uint8 *)(volatile float CYXDATA *)&wpm,2u);

   

How do I read the float back from EEPROM?

   

   

RegPointer = (reg8 *) (CYDEV_EE_BASE + (CYDEV_EEPROM_ROW_SIZE * 2));
index = 0;
f_wpm = RegPointer[index];
//OR THIS
memcpy(&f_wpm,&RegPointer,(sizeof(float)));

       

   

I'm ashamed to ask, but I can't get it to work.  I have been able to get the application to work using Emulated EEPROM but I would rather be able to use the EEPROM to store the data that needs to persist over reboots of the device.  The version of the PSOC 3 chip I am using has 256K of EEPROM so I know I have more that enough space to do what I need to.

   

Regards,

   

Ron

0 Likes
5 Replies
Anonymous
Not applicable

1. The &f_wpm and  &RegPointer are the same address.

   

2. What is the problem? Can't build? Won't read? 

   

3. How about post the project here?

0 Likes
ETRO_SSN583
Esteemed Contributor

When you write typically you write a whole row at a time. One

   

way of handling various variable sizes is a structure. You know

   

the length of the sturcture in bytes from its definition, so when you

   

go to access for a read you use a pointer to EEPROM staret of structure,

   

and another to the start of structure in RAM. You read a byte at a time from

   

FLASH, write the byte to RAM structure via its pointer, then inc both pointers.

   

 

   

Also I think there is a little confusion over EEPROM vs FLASH. Your chip

   

has 256K of FLASH, not EEPROM. But you can use FLASH as emulated

   

EEPROM, although its lifetime for write/erase cycles substantially less

   

unless you use an aging algorithim which moves to a new section of

   

FLASH when you hit the R/W cycle limit in a particular area of FLASH.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thanks for the responses.  I will give it another go based on what I have read.   Yes, it is not 256K EEPROM,  it is 2K.  My mistake.  

   

The project does compile and run properly with the exception of the floats not working properly.   Previously I had all the data required to persist through reboots stored in Emulated EEPROM.  This I found much easier to manage as the APIs for Emulated EEPROM are easier to use and no knowledge of the underlying hardware is required.  However, I decided to attempt to use EEPROM to free up just a bit more space in the flash memory and to use EEPROM for its intended purpose (to maintain data that needs to persist over reboots.  As previously mentioned,  the byte sized variables work fine.  It is the floats that I am experiencing issue with. 

   

 

   

I have attached the source file that contains the code used to manage the EEPROM variables.  

0 Likes
Anonymous
Not applicable

Here is the complete project.

0 Likes
ETRO_SSN583
Esteemed Contributor

Examine the float in memory to see how its stored, then

   

code appropriately the translation back to RAM using pointer.

   

Eg. get the byte order synched.

   

Regards, Dana.

0 Likes