cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

MaWo_1214996
New Contributor II

Hello,

I have problems with the following code, writing and reading data to the EEPROM.

I always get not the same read back as I was written to the EEPROM. I have created a project based on the EEPROM Example and it works fine.

            EEPROM_Start();

            CyDelayUs(20);

            EEPROM_UpdateTemperature();

            EEPROM_WriteByte(MotorSpeed_RUN , 0);

           

           

            EEPROM_UpdateTemperature();

            MotorSpeed_RUN_Read = EEPROM_ReadByte(0);

            EEPROM_Stop();

           

            if (MotorSpeed_RUN == MotorSpeed_RUN_Read)

            {

                Pin_LED_Green_Write(1u);

                CyDelay(2000);

                Pin_LED_Green_Write(0u);

            }

            else

            {

                Pin_LED_Red_Write(1u);

                CyDelay(2000);

                Pin_LED_Red_Write(0u);

            }

Is this maybe a problem with interrupts? I am using USB HID transfers every 10ms. Same as in the sample project of the AN82072.

0 Likes
Reply
3 Replies
odissey1
Honored Contributor II

Mark,

Try this component for storing data into EEPROM.

myEEPROM: component to save/recall application settings in EEPROM between power offs

If problem persists, then it could be an issue with timing - writing to EEPROM takes approx. 20ms.

/odissey1

0 Likes
Reply
MaWo_1214996
New Contributor II

Thanks Odissey1,

I have tried this component with the same result. There is still a warning with your component during initializing, I have used Creator 4.2.

I have the project attached, please have a look.

I also think it is about timing, I use USB HID report with 64 Bytes, but I have increased the interval already to the maximum of 255 ms.

If I use the EEPROM in separate projects, it works fine.

I think I basically need something like:

If EEPROM data needs to be written, stop(halt) everything and do only the EEPROM function, then when finish, continue with the rest as usual. If I lost some USB transfers, that would be acceptable. The EEPROM function need to be only executed, if new(different) data available for the EEPROM.

I am no looking into the topic interrupts to see if I can solve the problem that way.

Mark

0 Likes
Reply
himam_31
Employee

Hello,

Can you please check the return values of the function EEPROM_WriteByte(). Did it actually write the data successfully?

Also can you try calling EEPROM_Query() before writing to the EEPROM?

Thanks,

Hima

0 Likes
Reply