Problem using em_eeprom

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

cross mob
lock attach
Attachments are accessible only for community members.
paan_1335986
Level 1
Level 1

Hello,

This is the first time I write to the cypress community. It is a great place to find the solution to most PSOC problems.

I having problems using the em-eeprom on a PSOC 4 (CY8CKIT-049-42xx)

I have attached the complete project for you to see. It is a simple device that moves a hotmelt glue doser a few millimeters with a stepper motor (the project is not finished yet)

It has a lot of switch and a LCD character screen to set up 5 different parameters. I want to set the parameters and store them on flash to keep them on power cycles.

But it doesn´t work. I have read all forum thread on em_eeprom but I cant find the problem.

When I debug the project (using a kitprog from another kit) I see that the flash area is modified when the eeprom_write function is called. it is stored on the 184C address, and I do see it modified with the ram buffer data.

But this doesn´t happens on the target circuit.

Anyone find something wrong on the program?

Thanks in advance to all of you!!

Pablo

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

I had the same problem. The reason for that is the statement

LCD_PrintNumber(eepromArray[0]) refers to something that was declared (necessarily) as const. The compiler "remembers" the const value and inserts it instead of reading back the current value.

When you change the declaration to

static volatile const uint8 CYCODE eepromArray[51] = ...

it will work, but gives a warning.

I usually did these things a bit differently:

I declared my EEProm area as a struct. The first element (a 32bit int) as a "Magic Number" indicating a successful initialization,

The second element holds the number of writes to the EEProm.

The rest of the struct is my application data.

At the beginning of the program I check for a valid Magic Number, if not I initialize the EEProm with correct data.

I read back the EEProm data into a SRam area which from now on I access.

When required I write back the SRam to EEProm updating the write count.

Bob

View solution in original post

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

I had the same problem. The reason for that is the statement

LCD_PrintNumber(eepromArray[0]) refers to something that was declared (necessarily) as const. The compiler "remembers" the const value and inserts it instead of reading back the current value.

When you change the declaration to

static volatile const uint8 CYCODE eepromArray[51] = ...

it will work, but gives a warning.

I usually did these things a bit differently:

I declared my EEProm area as a struct. The first element (a 32bit int) as a "Magic Number" indicating a successful initialization,

The second element holds the number of writes to the EEProm.

The rest of the struct is my application data.

At the beginning of the program I check for a valid Magic Number, if not I initialize the EEProm with correct data.

I read back the EEProm data into a SRam area which from now on I access.

When required I write back the SRam to EEProm updating the write count.

Bob

0 Likes

Thanks for your answer Bob.

I declared the array as you said 

static volatile const uint8 CYCODE eepromArray[51] = ...

But now I get an error on the status return of the EEPROM_Write function and the data is not saved.

The array should be declared inside the main() ?

On the other hand, I like the idea of using a struct. How do you initialize it?

Pablo

0 Likes

"using a struct. How do you initialize it?"

Not as easy, have a look here.

Bob

0 Likes
paan_1335986
Level 1
Level 1

Hello. In case anyone had the same problem. The solution was to add "*(volatile int *)"  before reading the flash variable. So to read the non volatile are back I used:

// recall memory saved last time       

        for (i = 0; i < 51; i++)

        {

            ram_settings = *(volatile int *) &memory;

        }

It was my big mistake. Since this (volatile int) was mentioned at the end em_eeprom datasheet and I missed it.

Regards,

0 Likes