memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

memory

1,074 Views
aurora
Contributor I

I am using a MC908QC8CDRE MCU. How do I save one byte data to the RAM and retrieve the data when the MCU is connected to power source again?

 

I wrote a program for turning (controlling) on/off three LEDs (RED, Green and Blue) from a push button switch. Only one LED will be on at a time. I have setup a global variable for tracking which LED is turned on. After the user turns on the LED, the MCU will be disconnected from power source. When the MCU is connected to power again, I need to have the MCU to turn on the LED was selected. In other words, I need the MCU to remember the selection when it is disconnected from power. I think I need to save the information to the RAM, and then get the information back to a global variable when MCU power is recovered. Can anyone provide me an example in assembly code format?

 

Thanks,

hliu

Labels (1)
0 Kudos
4 Replies

494 Views
bigmac
Specialist III

Hello hliu,

 

The complexity of the process will depend on how many times, within the life of the product, the power is removed and re-applied.  The flash memory has a limited number of erase and write cycles before "wear out" occurs.  The simplest case is to erase a 64 byty block, and then write to the same address within the block, each time the value needs to be saved.

 

As the number of times that the parameter needs to be saved increases, the single byte value will need to be programmed to a number of successive locations within the block, and then whenever the block becomes full, the block would be erased, and the process startted again.  This would spread the wear over the whole block.

 

The MCU you are using contains erase and programming routines within ROM to simplify the process.  The MCU datasheet mentions that their use is described within application note AN2635.  The datasheet also references some other application notes that provide for EEPROM emulation with spread wear.  As these represent a general approach, the associated code will be quite complex.

 

If your project should require the wear spreading method, it should be possible to simplify this process since the active byte values used can most likely avoid the unprogrammed value ($FF) for the flash.  Therefore the most recent active value within the block can be very easily determined.

 

Regards,

Mac

 

0 Kudos

494 Views
aurora
Contributor I

Hi Mac,

 

I don't have to warry about "wear out" flash memory, this device only uses once per week for few minutes. In order to save battery power, the device is disconnected from power source when it is not in use. I read the application note AN2635, so far I am not 100% understand. But I tried following way for saving 1 byte data onto flash memory with following code,

 

Saveflash equ  $EDF8

......;

LDA   #$FF

STA   Saveflash

......;

When I run CodeWarrior debug, it gives me an error which show that "At location EDF8, Attempt to use unimplemented (--) memory".

 

What I have done wrong?

 

hliu

0 Kudos

494 Views
bigmac
Specialist III

Hello,

 

Since Saveflash is an address in flash memory, simply writing to this address will not work, as you have discovered.  Flash memory requires to be programmed, rather than written, but you must firstly erase the flash block (starting at address $EDC0) before programming the byte value 

 

Unless you arrange for your own routines to be executed from RAM, you will need to use the existing ROM based routines ERARNGE and PRGRNGE, as described in the application note.  You will also need to setup some specific Z_RAM  memory locations prior to calling each sub-routine.  The application note also details this requirement.

 

You would read the contents of the NV data in the same way as you would read any other memory address.

 

I would suggest that you use the first 64-byte flash block to contain your NV data.  The FLBPR register can then be programmed to protect the code and data at higher addresses from being overwritten.

 

Regards,

Mac

 

0 Kudos

494 Views
aurora
Contributor I

Thanks Mac for the suggestion, I will study the application note AN2635.

 

Thanks again,

 

hliu

 

0 Kudos