Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years ago.
Saving and retrieving data from local non volatile memory
I am making a single phase digital energymeter using the mbed LPC1768 platform. The code is ready and tested to be working as expected. But there is a slight problem, every time the microcontroller is powered off, the energy value gets lost as its in the RAM. In an ideal case the meter will always be powered on, but i want to insert a safeguard just in case there is power loss to the meter. So is there any way to efficiently save the energy data to a nonvolatile memory and then retrieve it back whenever i need to? Ideally what i would want to do is save the data to the non-volatile memory after each cycle of calculation and retrieve it at the beginning of the code once such that the saved value is used further in the program in case of a reset. The energy value is getting stored in a variable called "energy" in the program. I need to save this variable only. If anyone has a working code to do something like this please help me out. I dont want to use any external devices like SD card etc.
2 Answers
9 years ago.
If you are using the mbed LPC1768 device then you should be able to store the data in the LocalFileSystem.
The HelloWorld example on that page shows you how to initialize the LocalFileSystem and then use standard C functions like fopen(), fclose(), etc to access files within the LocalFileSystem. You may also want to perform a Google search for other standard C routines like fread(), fwrite(), fseek(), etc to write and read your data.
posted by 20 Apr 20159 years ago.
You can use registers RTC. Look at the user manual, chapter 27.6.6.1
Is very easy to use one of theses registers in one of your programs, register 0 is for instance LPC_RTC->GPREG0
save a char x
LPC_RTC->GPREG0 = x;
Provide a backup battery (pin VB) .