We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear Sir,
I am using ADUC841 microcontroller from Analog devices,which consists of 8052 core.In this it is having 4Kbytes of Flash data memory.I wrote the routines as mentioned in application note for writing the data in Flash.But the data is not storing in Flash.So,please send me some guidelines for writing the data in Flash.
Thanking you,
Yours sincerely, Shivakumar Manda
"So, please send me some guidelines for writing the data in Flash."
Surely, those guidelines are given in the Application Note?! Re-Check what you've done against the application note, and the Datasheet.
Nobody else can do that for you without seeing your code, can they?!
I had read the datasheet and according to that only i wrote one simple program to store the bytes in one page.Here I am sending the function statements to write the bytes in data memory.
void Flash_Mem_Write_Page(void) { EADRH=0x00; //Select Address hoiher byte EADRL=0x01; //Select addres lower byte
EDATA1=0x12; //writing the data EDATA2=0x13; EDATA3=0x14; EDATA4=0x15;
ECON=0x02; //writing the bytes Sleep(40); ECON=0x04; //verifying Sleep(22);
if(!ECON) //match is there it will return 0in ECON printf("WRITE\n"); else printf("NOT WRITE\n"); }
Thank you very much for replying.
"I had read the datasheet"
I hope you read it more carefully than the instructions here for posting source code:
www.danlhenry.com/.../keil_code.png
You also, apparently, didn't notice the problem in the 'Preview' - I hope you've reviewed your own code more carefully?
First, you said, "I wrote the routines as mentioned in application note"
Now you say, "I had read the datasheet and according to that only i wrote one simple program" (my emphasis)
So which is it - datasheet or application note?
or both?
or what?
Well, if you wrote the code according to the datasheet, did you also see the note that the bytes in the flash must be erased before new data can be written to them ?
Also, what is the point of the calls to sleep() ?
Seems like the calls to sleep are to allow time for the flash programming operation to occur. Erases are very slow; writes are not that bad, but still slow.
I haven't checked the data sheet, but most flash parts have a way to check to see if an operation is complete, rather than just waiting the worst-case time. I'm usually a little more comfortable with that sort of handshake than a hard-coded delay. But sleeping for longer than the worst-case time spec'd in the datasheet should work.
Seems like the calls to sleep are to allow time for the flash programming operation to occur.
It seems like that to me too, but I was asking for an answer from the OP - if he wrote his code according to the datasheet, then he should have noticed that it is not necessary to manually wait for anything when writing to the flash - the CPU will idle automatically until the write operation finishes. When the next instruction after the write command executes, the write operation is already over.
(Yes, this means that the chip may well spend several milliseconds doing nothing, including not responding to interrupts)
Look at followed example. It works on ADuC847.
// **************************************************** // save 4 bytes to addr 0x3FF // **************************************************** void SaveSetPointToFlash(unsigned char* puc) { EA = 0; // Disable interrupts before saving EADRH = 0x03; // High byte of page Address EADRL = 0xFF; // Low byte of page Address EDATA1 = puc[0]; // Data to flash EDATA2 = puc[1]; // Data to flash EDATA3 = puc[2]; // Data to flash EDATA4 = puc[3]; // Data to flash ECON = 0x05; // Erase Page ECON = 0x02; // Write Page ECON = 0x04; // Verify Page EA = 1; // enable interrupts after saving }
As notes Christoph you should provide erasing page and remove delays.
chip may well spend several milliseconds doing nothing, including not responding to interrupts Yes, we should not think about flash like about operational memory. It is hard drive on chip and as hard drive it is slow.