4 Replies Latest reply on Dec 12, 2017 11:54 AM by paan_1335986

    Problem using em_eeprom



      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!!



        • 1. Re: Problem using em_eeprom

          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.



          • 2. Re: Problem using em_eeprom

            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?



            • 3. Re: Problem using em_eeprom

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

              Not as easy, have a look here.



              • 4. Re: Problem using em_eeprom

                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[i] = *(volatile int *) &memory[i];



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