Writing variables to nonvolitile memory using xdata
My MCU is ADuC841 it had (working with SDK)
62 kBytes on-chip Flash/EE program memory 4 kBytes on-chip Flash/EE data memory
I want to store variable that i get from the serial port and write them to the EEPROM then turn off, turn on the MCU and read them some how (print the stored variable to screen = Hyperterminal) or using interrupt that prints it to screen.
my code is working on the the simulator of keil i see the memory window but on then target MCU it doesn't work
My code:
unsigned char xdata large_array[20] _at_ 1500; unsigned int xdata timer_tick; void INT_EX0() interrupt 0 { puts(large_array); } void main (void) { while(1) { T3CON = 0x87; // 4800 T3FD = 0x08; SCON = 0x52; IT0 = 1; // Configure interrupt 0 for falling edge on /INT0 (P3.2) EX0 = 1; // Enable EX0 Interrupt EA = 1; puts("\nEnter string :"); getline(large_array); // get string from serial port puts(large_array); // read from memory and output to serial port } }
the output of the MCU on Hyperterminal is something like all the char in ascii - "abcdefg...!@#$%^&*()..."
WHAT IS THE PROBLEM ??
Thanks in advance !!!
Mayer
You really have to start reading datasheets before writing code. The data flash on this device is not, repeat: NOT, accessed like xdata.
Hans thanks for your answer
I read the data sheet and there is about 6 sfr that handle with the data\program memory
My question is that - can i do wiritng to the EEPROM without all this registers by using XDATA or i must use those register (ECON,EADRH\L,EDATA1-4) ??
Exmple code from data sheet www.analog.com/.../ADUC841_842_843.pdf (page 34)
program tha data F3H into the second byte on Page 03H of the Flash/EE data memory space
ECON = 6; // Erase all memory EADRH = 0; // high byte EADRL = 3; // low byte ECON = 1; // Read Page into EDATA1-4 EDATA2 = 0x0F3; //overwrite the second byte ECON = 5; // ERASE Page ECON = 2; // WRITE Page ECON = 4; // VERIFY Page if (ECON == 0) // Check if ECON=0 (OK!) ERROR(); // fuction that handle the error
Is that the only way to program the EEPROM ???
How many other ways are listed in the Datasheet...?
My question is that - can i do wiritng to the EEPROM without all this registers by using XDATA or i must use those register
those amazing designers of chips just add all those SFRs because they think it is fun to do so.
Do you REALLY ASS U ME that all that is there "just to confuse you"?
Anyhow, there is, somewhere, a "manhandled" banking routine that makes an EE appear as a (painfully slow) bank of XRAM. Since I do not use it, my recollection is a bit fuzzy, but I think it is for an external EE so you will have to modify it to use and thus you must "use those registers".
Now I brought the subject up, I guess someone using it will locate it for you and, maybe, have some comments on it.
Erik
Andy, Hans
I read the datasheet as you said (i did it before i started the thread)
In the datasheet i saw that there is only one way to program the EE/FLASH data memory.
But this method of programing is very (relatively) complex. Using 6 sfr to program one char (i.e 'A') is too much in my opinion ?!?!?
My question is that :
All MCU that i want to program there EE/FLASH data memory is in that "fashion" ?? (using few sfr do to a little change in the EE/FLASH data memory)
Using an array of varibles in C (int for example) is very easy (opposed to ammebler to an array relatively is harder)
What is the advantges of "C" on assembler in this issue ?? (writing to the EE/FLASH data memory)
The solution for my first question (writing to the EE/FLASH data memory - with few changes)
http://www.keil.com/download/docs/184.asp
Using 6 sfr to program one char (i.e 'A') is too much in my opinion ?!?!?
Sorry to burst your bubble, but your opinion is entirely irrelevant in this regard. As is anybody else's, lest they happen to be MCU designers.
And BTW, writing a single char doesn't take 6 SFRs --- 4 are quite sufficient.
All MCU that i want to program there EE/FLASH data memory is in that "fashion" ??
How could anyone possibly answer that? Nobody but you knows what "All MCU that i want to program" means.
What is the advantges of "C" on assembler in this issue ??
None. So what?
View all questions in Keil forum