C51 compiler - write to xdata

Programming on the XC888 microcontroller, I want to save a buffer for some data in the external xdata memory.

I do it like this (just an example where I got rid of unnecessary code):

header.h

 extern ubyte xdata rec_buffer[32]; 

function.c

 ubyte xdata rec_buffer[32] = {0}; void foo() { //Option 1 rec_buffer[0] = 0xFF; // Doesn't work //Option 2 ubyte xdata *ptr_buf = rec_buffer; ptr_buf[0] = 0xFF // Doesn't work } 

So I just can’t understand what I don’t see here. In both cases, data is not written to the buffer. (Tested using the debugger). I also checked the address pointed to by pointers -> It actually points to external memory (address 0x000000 , but there should be nothing wrong with that).

When I do this without defining a buffer in xdata , it works completely fine. What am I doing wrong? Is there any special way to write in xdata?

+4
source share
2 answers

Shouldn't XRAM be 0xF000 (not 0x000000 )? According to Figure 7 here:

http://www.keil.com/dd/docs/datashts/infineon/xc88xclm_ds.pdf

Wrong linker layout?

+5
source

Use the volatile keyword for your buffer, most likely the variable is skipped by the compiler. If you write a value to memory or an I / O space but don’t observe the value or any changes, your variable is most likely optimized by the compiler.

0
source

All Articles