How to save to a variable to memory and recall it after a power cycle

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.
HeLa_4671121
Level 1
Level 1
First like received First like given

Hello-

I'm new to the PSoC world and I need some help.  I have a program that has two timing variables that I can change through the mini-USB UART port while the program is running (with Putty).   What I would like to do is be able to save the changes to a memory location so that when the power is recycled, the PSoC recalls the last saved value.  The only user communication connection to the PSoC will be the mini-USB.

I'm using the following kit:  CY8CKIT-059 5LP

Using two variables to control the length of time for CyDelay within a function. 

uint32 ftime =(3000);   //3 Sec default - Variable #1
uint32 btime =(3000);  //3 Sec default - Variable #2

I'm using a switch statement to be able to vary these timings anywhere from 1 - 5 secs depending on user preference.

I'm using the uint32 because that is data type that the CyDelay wanted.  What would be the easiest way to do this?  I've looked at both em_EEPROM and Flash but I'm too unexperienced to figure it out.  My program is also printing status updates to the USB port.  Is it possible to display the recalled value on the USB port?  Attached is my project, please be kind as this is my first time working with PSoC and writing C code .  If anyone has example code or wants to tweak mine, it would be greatly appreciated.  

Thank you,

Henry

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I added an EEPROM to your project.

From debugger, it seems to be working,

but without debugger, with my environment, it's difficult to very if it's working.

Anyway, I'll be glad if this can be a hint for how to use EEPROM.

moto

View solution in original post

0 Likes
10 Replies
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Henry,

There is a custom component and two demo projects which accomplish just that. The easy one (save-recall-exit):

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

The original demo project which does exactly what you asking:

1. start and reload settings from EEPROM if available, else use default

2. update and save settings

3. re-start and reload last settings

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

/odissey1

0 Likes

BoTa-

Thank you for the reply.  When I try to run this program, the UART port does not activate.  In the device manager, all I see is my programmer (MiniProg4) and no other active ports.  Is there something I need to do?  I know the cable is good and the port is good because my original program is working.

Do I need to do anything with the myEEPROM_lib.cylib folder?  Everything complied and programmed without any errors. 

Henry

0 Likes

Henry,

What kit are you using? Below I will assume that it is CY8CKIT-059 Prototyping kit.

Start with basic demo which was last compiled using CY8CKIT-059 prototyping kit

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

Notice that UART TX output is connected to the specific pin 12_7. This pin is hardwired to the USB-UART converter located on the KitProg. So when you run the program, you should see extra COM port.

The original demo

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

was compiled for FreeSoc 1 board long time ago, when KIT-059 didn't exist. It doesn't have USB-UART converter built-in, like KIT-059.

In general, to see the COM port on PC one need to have USB-UART converter, as modern computers don't have COM ports available. I usually use FTDI USB-UART dongles with 5V i/o.

/odissey1

UART_Rx_schm_01a.png

0 Likes

/odissey1-

I was able to get your example to work.  I had a few issues, the EEPROM component in my PSoC Creator 4.3 library was different from the one in the example.  When I tried to use the current component, I got programming errors.  I noticed something in the readme file and added the library folder as a dependency.  I ended up copying and pasting the myEEPROM component from the example into my schematic and then I was able to get it to work.

From the example

pastedImage_0.png

From PSoC Creator 4.3

pastedImage_2.png

As for the UART, I switched it out for the USBUART and now have an active comm port with live data.  I don't have the regular UART pins connected on the PCB, but I am familiar with the RS232-USB adapters.

The kit I am using is in the CY8CKIT-059 5LP.

moto-

Thank you for taking the time to modify my code.  I will have to chew on it for a bit and try to understand what it is doing.  I noticed you are using the standard EEPROM 3.0 component so that makes we want to investigate further.

Thank you both for your help and the quick responses.

Henry

0 Likes

Henry,

Do not use extra EEPROM. The EEPROM component is already included into myEEPROM. Any time a new version of the EEPROM is released, all you need to do is to update components in the project: Project->Update Components and then follow menu commands. Another way is notice  a small brown shield appeared in the bottom-right corner. It shows up every time newer version of a component is detected. Click this icon and follow the Update Components menu.

It is likely that Creator 4.3 had updated EEPROM version, and refused to work until Component Update is performed.

If you are using KIT-095 the additional Com port should appear in the menu. You don't have to connect anything to Pin_12[7] outside. Occasionally this extra com port doesn't want to show and then simple unplugging/plugging from PC usually helps.

Note that if using external adapter, it should not be RS232, which produces -12V and may damage the port. Use only USB-UART rated +5V (+3.3V won't work with KIT-059).

/odissey1

Thank you for the clarification.  Currently I'm using the on-board mini-USB and have it set at +5V operation. 

Is there any way to force the mini-USB port to use the power from the board and not the computer USB port?  My PCB has a 12V and 5V power supply to power outputs, logic and the PSoC, but I've noticed that the PSoC still has power from the PC.  The program is still active even though my power supply is off.

Or is there a way to pause the program if no power is detected?  I can always unplug the USB cable but that would get annoying after a while.

Thanks,

Henry

0 Likes

Henry,

>Is there any way to force the mini-USB port to use the power from the board and not the computer USB port?

- Not sure, but you can try to cut the +5V on the USB cable. Note that you have grounds and +5V Power supplies PCB to PC connected.

>Or is there a way to pause the program if no power is detected?

-You can check +5 voltage level from the Power supply using a digital pin and send PSoC it into Deep Sleep/Hybernate using API call. That might require some diode between power supply and PSoC. I think that using USB-UART dongle will be simpler. For example TTL-232R-5V-PCB

Do you program KIT-059 using a KitProg or an external Miniprog? Is KitProg still attached to the KIT-059? Do you need UART communication with PSoC other then debugging?

/odissey1

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I added an EEPROM to your project.

From debugger, it seems to be working,

but without debugger, with my environment, it's difficult to very if it's working.

Anyway, I'll be glad if this can be a hint for how to use EEPROM.

moto

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Dear Henry-san,

Since I have used some of my time modifying and preparing  the sample, I

would appreciate it if you also download and test my sample

and let me know if it works for you or not.

Best Regards,

6-Jun-2020

Motoo Tanakaa

0 Likes

Motoo-

Your sample works as well and it uses the EEPROM component that is included in my PSoC Creator 4.3.  There is a lot more going on with your sample so need to educate myself.  This is my first experience with PSoC and the trouble I'm having is sometimes the examples don't work with my device or an error is displayed that I have no idea how to address.  Thank you again for taking the time because a working example is priceless to a newbie.

Regards,

Henry