This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADuC812 evaluation board and xdata

I'm having some trouble reading and writing to external data memory on an Analog Devices ADuC812 evaluation board. I have two arrays declared as xdata in which I am storing values. According to dScope, the correct values are being written to external memory, but when I print the contents of the arrays to the serial port, I get unexpected results. Some of the values written to array 2 appear to be stored in array 1, and vice versa. Which values are stored where depends on the size of the arrays.

Here is my code. Is there something else I need to do to use external data memory?

#pragma CODE SYMBOLS

#include <stdio.h>              // declarations for I/O functions
#include <ADuC812.h>            // 8052 & ADuC812 predefined symbols

#define uint16 unsigned int
#define NSAMPLES 32

uint16 startflag;

/* INT 0 Interrupt routine */
void int0 () interrupt 0 using 1 {
  startflag = 1;
}
 
main() {

  uint16 xdata test1[NSAMPLES];
  uint16 xdata test2[NSAMPLES];
  uint16 index;

  startflag = 0;

  /* Configure UART */
  SCON = 0x52 ;                 // 8bit, noparity, 1stopbit
  
  /* Configure timer 1 for 9600 baud */
  TMOD = 0x21 ;                 
  TH1 = 0xFD ;                  
  TR1 = 1;						// start timer1
	
  IT0 = 1 ;		    			// make INT0 edge-triggered
  IE = 0x81 ;           		// enable INT0 interrupt

  while (!startflag);
  for (index = 0; index < NSAMPLES; ++index) {
    test1[index] = 500;
    test2[index] = 1000;
  }

  printf("Array1\tArray2\n");
  for (index = 0; index < NSAMPLES; ++index) {
    printf("%u\t%u\n", test1[index], test2[index]);
  }

  while(1);
}

Here is an example of the output, in this case for arrays of 12 ints:
Array1	Array2
1000	1000
1000	1000
1000	1000
1000	1000
1000	1000
1000	1000
1000	1000
1000	1000
500	1000
500	1000
500	1000
500	1000