Hello!
I'm using a AT89c51RC Controller for my application.
When I define global variables with an initial value, they are not always initialized correctly.
Example:
signed int test=3;
If I place the variable on the beginning of the xdata memory space, then they are initialized correctly. But if I place the variable at the back of xdata, they have wrong values like -16235.
I have deleted or commented out all loops in my programm, so there cannot be a memory overflow, that is produced be me.
If I initialize the variables later within my program manually, everything works correctly -> so the error must occur before the program starts.
I also checked out the amount of xdata that is used by my program, but its far from being full.
Is it possible, that there is an error in the startup.a51 or init.a51 files?
I use no reentrant functions, so I disabled the XBPSTACK but that changed nothing ...
Maybe someone can help me or give me a hint
Josef
But if I place the variable at the back of xdata, they have wrong values like -16235.
a recollection, which may not apply, is that some chips have been described (AARGH) with memory size that include both (I)DATA and EDATA e.g. 1k will give you 768 bytes of ERAM ("internal external RAM). I DO believe the RD2 is one of those, check your datasheet
could that be the case for you?
some write/reads will work in nonexisting memory, due to incomplete (but sufficient) address decoding and then be overwrittn by writes to another matching address.
Erik
PS I fell in that trap once :(
"incomplete (but sufficient) address decoding" above should have been:
"incomplete (but sufficient when staying within range) address decoding"
If I place the variable on the beginning of the xdata
Why would you place variables anywhere specific? If you interfere with the linker's own placement of variables like that, odds are significant that you'll break the startup code's ability to initialize variable properly.
I only placed the variable in at different subroutines of my program to check if initialization works correctly. So i found out, that variables on the beginning of xdata are initialized corrctly.
Then I found out something interesting: On start of my C-program i set the AUXR Register to value 0x0c to change the size of xdata from 256 bytes to 1024 bytes. After this command variables in xdata with an address greater that 0x100 have wrong initialization values.
"On start of my C-program i set the AUXR Register to value 0x0c to change the size of xdata from 256 bytes to 1024 bytes. After this command variables in xdata with an address greater that 0x100 have wrong initialization values."
I'd have thought that was entirely to be expected?
On start of my C-program i set the AUXR Register to value 0x0c to change the size of xdata from 256 bytes to 1024 bytes
Please read the manual
www.atmel.com/.../doc1920.pdf
states
4. The 256-byte expanded RAM (ERAM, 00H-FFH) is indirectly accessed by MOVX instructions, and with the EXTRAM bit cleared.
I could not get '768' of my head and I just had to look up the P89c51RD2. Voila! there is the 768 bytes of ERAM. Of course Josefs 1k is still wrong, especially since he is using a RC. Arghmel and NXP both have only 256 bytes ERAM in the RC
for the P89C51RD2 4. The 768-bytes expanded RAM (ERAM, 00H – 2FFH) are indirectly accessed by move external instruction, MOVX, and with the EXTRAM bit cleared, see Figure 38.