Question

Well I hope this question fits to Stackoverflow ( if otherwise, I want to apologize already )

I have can C8051F340 Microcontroller from Silabs. I wrote a little Interface which stores Information in the non-volatile flash memory from the uC. Now as in the data sheet described I save all the data in between the addresses 0x0200 - 0x0300. To copy my data there I just use memcpy.

char xdata *ptr_selection       = 0x0210;
// Some other code here
memcpy (ptr_selection, writeBuffer, sizeof (writeBuffer));

Well the copying itself works well ( I looked up at the flash memory and it saved my data right ) - If I now disconnect my uC and connect it again in like 5 secs, the data is still there. But if I leave it disconnected any longer my data gets more or less "resetted" - that means it gets everytime almost the same "reset values". so what am I doing wrong? I mean isnt the flash data non volatile or did I get something wrong?

Was it helpful?

Solution

Based on the code you displayed in your question, you are trying to write to external data (xdata), which is RAM, not non-volatile flash memory. The reason the data disappears after a few seconds, is the power supply capacitor still powers the chip long enough to keep the internal RAM alive.

To write to flash memory, you need to follow a specific protocol to unlock the flash programming circuitry, then erase the area you will be writing to, and then write the bytes using MOVX instructions as described in Section 12 of the datasheet.

This Silicon Labs application note "Writing to Flash from Firmware" describes the process in detail.

OTHER TIPS

Flash memory is not like oridnary SRAM, SDRAM memory.

You can not just write to it. Maximum that you can - read from it as from normal memory (only if you have NOR flash).

But if you want to write to it, you have to the first of all erase it (set all bits to 1). Only then you can write to it. Normaly, erasing done by sectors. They called erase sectors. See datasheet of your microcontroller about their size.

PS

Acording to datasheet of your CPU, to write you have to use special instruction. Make sure that memcpy internally use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top