Emulated Eprom in PSoC 4

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 I'm trying to use the emulated eprom (version 1.10) in PSoC 4 to save some data.  My flash is almost full, I have about 4k bytes left.

   

  This code came from PSoC 5, where the eeprom exists, and I may wish to take it back again, so some things are left in place.

   

  The problem is the write call happens, and does not complain.  However, the data is never written to the flash variable "settings."  It always retains its old value.  If I don't initialize it, it remains a value of "0" after the write.  Data sheet recommends initializing.

   

   Has anyone gotten this to work for the PSoC 4?  It works well in EEPROM for PSoC 5.

   

wade

   

Code:

   

 

   

typedef struct eeprom_data_struct {
    union {
    float f;
    uint8 b[sizeof(float)];
    } offset;
    union {
        float f;
        uint8 b[sizeof(float)];
    } slope;
} EEPROM_DATA;
 

   

EEPROM_DATA ramSettings;
const static EEPROM_DATA settings = {{1.094},{3.072}};

//-----------------------------------------------------------
//-----------------------------------------------------------
void read_eeprom() {
EEPROM_Start();
    offset = settings.offset.f;
    slope = settings.slope.f;
    ramSettings = settings; // copy into ram
    EEPROM_Stop();// power down the EEPROM
}

//-----------------------------------------------------------
//-----------------------------------------------------------
void saveSettings() {
    EEPROM_Start();
    ramSettings.slope.f = slope;
    ramSettings.offset.f= offset;
   
     
    EEPROM_Write((const uint8*)&ramSettings,(const uint8*)&settings,sizeof(ramSettings)); // write first 16 bytes in one fell swoop
    EEPROM_Stop(); // power down the EEPROM
}

0 Likes
10 Replies
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

There is an example project here that may be of help -

   

 

   

    

   

          http://www.cypress.com/?rID=105775

   

 

   

www.element14.com/community/community/design-challenges/smarter-life/blog/2013/11/24/psoc-4-tricopte...

   

 

   

Regards, Dana.

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 '  Thanks,  I'll look into it.

   

  At first glance, the code is pretty much the same pattern, unless making local variables does something special for the code.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Also in Creator SP2 just released there is this update/fix -

   

 

   

   

 

   

Regards, Dana.

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 Just installed SP2 today and tested on it.  Even when running full speed without debugging, it fails.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I did not have problems with the em_eeprom component yet. Will you mind to post your complete project (or a reduced example) that shows the error? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file. So we all here can look at all of your settings.


Bob
 

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

We had that issue before, it is a compiler flaw, your eeprom is written correctly, but the assing of the eeprom-data to your ram data fails. The compiler "knows" that your variable "settings" is a constant and has kept the values in "mind". When you now issue a

   

    ramSettings = settings; // copy into ram

   

the compiler takes the values and fills ramSettings with those.

   

Use a memcpy() to shuffle the informations from eeprom to ram as in my attached project.

   

 

   

Bob

Thanks,

I had the same problem,

the memcpy works for me

0 Likes
WaMa_286156
Level 5
Level 5
First comment on blog 100 replies posted 50 replies posted

 thanks!  I'll give that a try.  It will take a day or two, other things are commanding attention at the moment.

0 Likes
Anonymous
Not applicable

Hi,

   

this is a question for Bob Marlowe about his nice example PrototypeKit4.cywrk.Archive01.zip

   

Why do you use the instruction memset between these to Ram2EEProm and EEProm2Ram lines?

   

Ram2EEProm();
memset(&RamData,0,sizeof(struct EEEPromdata));
EEProm2Ram();

   

Thank you for your answer.

   

Best regards

   

Denis

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, Denis!

   

This was done just to verify when using the debugger that EEProm2Ram() filled the sram with new data.

   

 

   

Bob

0 Likes