9 Replies Latest reply on Sep 15, 2016 9:49 AM by user_1377889

    Emulated Eprom in PSoC 4

    user_463759797

       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
      }