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); }
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
I noticed in the output that the first 8 values are incorrect, then the next 4 are correct. Could this merely be a defective board? Is there a ram test that you can use, or perhaps some code with a scope to check the addressing. The code itself looks correct. Try putting the arrays in internal memory as a test, to verify correctness of the program. If the program works, then it would strongly indicate a board problem.
please define the uint16 such below you will get the correct result #define uint16 unsigned char
The problem was a defective board. It has since been replaced.