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

on-chip xdata on aduc832

Can anyone please help explaining me why this code won't access the on-chip xdata. When executing the below code nothing happens at all.

#include <ADUC832.H>
#include  <stdio.h>

void main (void)
{
  xdata int m[10];
  int j;
/*-----------------------------------------------
Configure the serial port to run at 9600 Baud.
-----------------------------------------------*/

        PLLCON = 0xF0; // core clock 16.78 MHz
        PCON |= 0x80;    // Set SMOD i.e. double baudrates
        SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
        TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
        TH1 = -9;            // TH1:  reload value for 9600 baud
        TR1 = 1;       // TR1:  timer 1 run
        TI = 1;

  for(j=0;j<10;j++)
    m[j] = j;

  for(j=0;j<10;j++)
        printf("int m[%i] = %i\n", j, m[j]);

        while(1);
}

In the startup code (START_AD.A51) I did enable xdata access

; XRAMEN     Val  Description
; ------     ---  -----------
XRAMEN EQU 1; 0 = disable on-chip XDATA RAM and access off-chip XDATA space
;           ; 1 = enable on-chip XDATA RAM

If I change to XRAMEN EQU 0 and run the code, the output is ten "-1" on the serial port (this I understand as xdata isn't available)

Parents
  • Oh I see, if I use the debugger I also get correct results. The debugger apperently assumes that off-chip XRAM is available and disregards the XRAMEN setting in the startup code.
    I have tested the code from my previous post on a second (and brand new) aduc832 board just to obtain the same result - no output on the serial port at all when using XRAMEN EQU 1.
    If I simplify my code even further to e.g.:

    #include <ADUC832.H>
    
    sbit LED = P2^0;
    void main (void)
    {
     unsigned int j;
    
     while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }
    


    Then still nothing happens when using XRAMEN EQU 1 - the LED connected to pin P2.0 remains in the same state

    However, if I exclude the STARTUP_AD.A51 from the project and do it in the following way, then the aduc832 board do as I expect it to.

    #include <ADUC832.H>
    #include  <stdio.h>
    
    #define MAX 1024
    
    sbit LED = P2^0;
    void main (void)
    {
     xdata int m[MAX];  // On-chip xram array
     unsigned int j;
    CFG831 |= 0x01;     // enable on-chip xram by setting XRAMEN
                        // in SFR ... funny name 'CFG831', why isn't
                        // named 'CFG832'
    
    /*-----------------------------------------------
    Configure the serial port to run at 9600 Baud.
    -----------------------------------------------*/
    
           PLLCON = 0xF0; // core clock 16.78 MHz
           PCON |= 0x80;    // Set SMOD i.e. double baudrates
           SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
           TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
           TH1 = -9;            // TH1:  reload value for 9600 baud
           TR1 = 1;       // TR1:  timer 1 run
           TI = 1;
    
     printf("Starting\n");
     for(j=0;j<MAX;j++) {
       m[j] = j;
           printf("int m[%i] = %i\n", j, m[j]);
     }
    
           while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }
    

Reply
  • Oh I see, if I use the debugger I also get correct results. The debugger apperently assumes that off-chip XRAM is available and disregards the XRAMEN setting in the startup code.
    I have tested the code from my previous post on a second (and brand new) aduc832 board just to obtain the same result - no output on the serial port at all when using XRAMEN EQU 1.
    If I simplify my code even further to e.g.:

    #include <ADUC832.H>
    
    sbit LED = P2^0;
    void main (void)
    {
     unsigned int j;
    
     while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }
    


    Then still nothing happens when using XRAMEN EQU 1 - the LED connected to pin P2.0 remains in the same state

    However, if I exclude the STARTUP_AD.A51 from the project and do it in the following way, then the aduc832 board do as I expect it to.

    #include <ADUC832.H>
    #include  <stdio.h>
    
    #define MAX 1024
    
    sbit LED = P2^0;
    void main (void)
    {
     xdata int m[MAX];  // On-chip xram array
     unsigned int j;
    CFG831 |= 0x01;     // enable on-chip xram by setting XRAMEN
                        // in SFR ... funny name 'CFG831', why isn't
                        // named 'CFG832'
    
    /*-----------------------------------------------
    Configure the serial port to run at 9600 Baud.
    -----------------------------------------------*/
    
           PLLCON = 0xF0; // core clock 16.78 MHz
           PCON |= 0x80;    // Set SMOD i.e. double baudrates
           SCON = 0x50;   // SCON: mode 1, 8-bit UART, enable rcvr
           TMOD = 0x20;   // TMOD: timer 1, mode 2, 8-bit reload
           TH1 = -9;            // TH1:  reload value for 9600 baud
           TR1 = 1;       // TR1:  timer 1 run
           TI = 1;
    
     printf("Starting\n");
     for(j=0;j<MAX;j++) {
       m[j] = j;
           printf("int m[%i] = %i\n", j, m[j]);
     }
    
           while(1) {
       LED = !LED;
       for(j=1;j>0;j++)
       {};
     }
    }
    

Children
No data