Using SST89E516RD controller, how to write the variable values into internal flash memory and read back from flash memory

23 Views Asked by At

I am working in SST89E516RD controller and KEIL c51 compiler using and new version. i want store the variable values into flash memory for power on cycle. for that I am using in_application_programming (IAP). how to use IAP? If i use the CODE keyword for variable, it is showing that unmodified value error is showing. how store the variable values into flash and read back when power is OFF and ON? can you please provide an example code.

I am expecting the brief logic code for one char value that is stores in FLASH memory and read it back when power is OFF and ON in 8051 controller. how to enable the IAP and how to unlock the security lock to the flash memory in 8051 controller?

1

There are 1 best solutions below

0
Clifford On

Flash is re-writable memory, but not "read-write" memory. Moreover, it typically has page block erase, so while you can write a single byte, you have to erase an entire page, and a byte can only be written if it is in the erased state.

Flash memory in it's normal state is read-only memory, and to erase a page or write a byte, you must set the memory controller to the write mode. The means by which that is done varies with specific MCU, and details will be provided in the data sheet. An MCU vendor may provide library code to perform write operations.

However you cannot simply modify a ROM resident variable as if it were in RAM. In fact because of the block erase constraint, you would more likely maintain the variable in RAM and initialise it (and other NV data) from ROM at start up, and write all variables as a block on modification. This requires special care (and code) to ensure the integrity of data in the event if a power failure while updating (flash writes and erase are very slow), and also to me minimise writebacks, because flash memory has limited "endurance", and erase/write cycle endurance may be as low as 10000 cycles in som parts, and typically no better than 100000.

Because if these issues, an alternative NV storage such as an external SPI or I2C serial EEPROM or FRAM might be a safer solution.

Now with all those caveats in mind the details for your specific MCU are defined from page 35 of https://ww1.microchip.com/downloads/en/DeviceDoc/25093B.pdf. The part has relatively small 128 byte erase blocks (or sectors), and endurance if 10000 cycles. A simple way of ensuring power fail safety is to main train two copies of the data and flip them on alternate writes, and include sequence and integrity checks, so you can determine which sector is current in start up. That also effectively doubles the endurance.