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

UART examples for ADuc7026

Hi there
I have problem with keil (even with AD code) example of UART

//******************************************
unsigned char memory_pool[0x400];
int main (void) { int iIterator; int iUserVar1 = 0; int *iArray;

GP1CON = 0x011; // Setup tx & rx pins on P1.0 and P1.1 // Start setting up UART at 9600bps COMCON0 = 0x80; // Setting DLAB COMDIV0 = 0x93; COMDIV1 = 0x00; COMCON0 = 0x07; // Clearing DLAB

// initialize memory pool init_mempool (memory_pool, sizeof(memory_pool));

// create an array big enough to hold 10 integers iArray = malloc (10*sizeof(int));

if(iArray == NULL) { printf("Malloc failed!\n"); } else { for(iIterator = 0; iIterator<10; iIterator++) { iArray[iIterator] = iIterator*2; } }

// demonstrate user input via scanf
// an alternative to scanf is gets and sscanf printf("please enter a number: "); scanf("%i", &iUserVar1); printf("\nUser Input: %i\n", iUserVar1);

while (1);
}

//******************************************
When I configure My Hyper terminal (as it should be
9600/2stop/no parity )
he displays that:
I can't open my COM port !?!?
When I change setting, example: 4800/2stop/no parity
there's no bad information, and something is transmiting to my PC- I see a "ee..##.e# ....etc.)

What is the problem?
regards and happy NEW YEAR

Parents
  • Hi there
    Sorry for code:/ It's my first time in here.

    so, code from KEIL is:

    /*
     *  IODEMO.C:  Demonstrates usage of printf, scanf and malloc with
     *             GNU Compiler (on ADuC7024)
     *  Copyright KEIL ELEKTRONIK GmbH and KEIL SOFTWARE, Inc. 2003 - 2004
     *
     *  This file may be compiled in ARM or Thumb Mode
     */
    
    
    #include <ADuC7024.H>
    #include <stdio.h>
    #include <stdlib.h>
    
    unsigned char memory_pool[0x400];
    
    int main (void) {
            int iIterator;
            int iUserVar1 = 0;
            int *iArray;
    
            GP1CON = 0x011;                                                 // Setup tx & rx pins on P1.0 and P1.1
                                                                                            // Start setting up UART at 9600bps
            COMCON0 = 0x80;                                                 // Setting DLAB
            COMDIV0 = 0x93;
            COMDIV1 = 0x00;
            COMCON0 = 0x07;                                                 // Clearing DLAB
    
    // initialize memory pool
       init_mempool (memory_pool, sizeof(memory_pool));
    
    // create an array big enough to hold 10 integers
            iArray = malloc (10*sizeof(int));
    
            if(iArray == NULL)      {
                    printf("Malloc failed!\n");
            }
            else {
              for(iIterator = 0; iIterator<10; iIterator++) {
                    iArray[iIterator] = iIterator*2;
              }
            }
    
    // demonstrate user input via scanf
    // an alternative to scanf is gets and sscanf
            printf("please enter a number: ");
            scanf("%i", &iUserVar1);
            printf("\nUser Input: %i\n", iUserVar1);
    
        while (1);
    }
    
    
    
    
    /***********************************************************************/
    /*                                                                     */
    /*  SERIAL.C:  Low Level Serial Routines                               */
    /*                                                                     */
    /***********************************************************************/
    
    #include <ADuC7024.H>                      /* ADuC7024 definitions          */
    
    #define CR     0x0D
    //int putchar(int ch)  __attribute__ ((used));
    //int getchar (void)  __attribute__ ((used));
    
    int putchar(int ch){                   /* Write character to Serial Port  */
    
            if (ch == '\n')  {
            while(!(0x020==(COMSTA0 & 0x020)))
            {}
                    COMTX = CR;                                                     /* output CR */
                    }
        while(!(0x020==(COMSTA0 & 0x020)))
        {}
    
            return (COMTX = ch);
    }
    
    
    int _getkey (void)  {                      /* Read character from Serial Port */
    
            while(!(0x01==(COMSTA0 & 0x01)))
            {}
            return (COMTX);
    }
    
    
    
    
    /***********************************************************************/
    /*                                                                     */
    /*  SYSCALLS.C:  System Calls Remapping                                */
    /*                                                                     */
    /***********************************************************************/
    
    #include <stdlib.h>
    
    
    extern int putchar (int ch);
    extern int getchar (void);
    
    int read (int file, char * ptr, int len) {
      char c;
      int  i;
    
      for (i = 0; i < len; i++) {
        c = getchar();
        if (c == 0x0D) break;
        *ptr++ = c;
        putchar(c);
      }
      return len - i;
    }
    
    /*      Write a buffer using putchar function in serial.c       */
    
    int write (int file, char * ptr, int len) {
      int i;
    
      for (i = 0; i < len; i++) putchar (*ptr++);
      return len;
    }
    
    int isatty (int fd) {
      return 1;
    }
    
    
    void _exit (int n) {
    label:  goto label; /* endless loop */
    }
    
    
    #define HEAP_START 0x10000000
    #define HEAP_LIMIT 0x10010000
    
    caddr_t sbrk (int incr) {
    //extern char   end asm ("end");      /* Defined by the linker */
      static char * heap_end;
             char * prev_heap_end;
    
      if (heap_end == NULL) heap_end = (char *)HEAP_START;//&end;
      prev_heap_end = heap_end;
    
      if (heap_end + incr >= (char *)HEAP_LIMIT) {
        abort ();      /* Out of Memory */
      }
      heap_end += incr;
    
      return (caddr_t) prev_heap_end;
    }
    
    
    

    according to your post:
    1.On different baud hyperterminal doesn't get real information , he gets trash .
    For example I send "hello",and he gets "ee"
    It's posible when he can't find the speed of data,
    exactly he gets broken characters-but its not the point of my problem!
    2.there isn't another program using my port ,I'm programing my Aduc7026 by UART(the same port COM1)with max3232 , then I disconnect my programmer software (ARMWSD software), and turn on Hyperterminal
    3.Bad information is now I don't have an oscilloscope.
    4.This case is quite unnormal for me, I'm not beginner, When I set the required parameters for
    transmission 9600/no parity/2bis he displays that:I can't open my COM1 port, but when I set incorrect
    parameters like 4800/no parity/2bis he gets broken characters-so he is transmitting something!
    I read datasheet and analysed the code, every thing
    is ok and there's no way to move this UART on correct param.
    The same COM1 port is working normally with UART on LPC2146/at91sam/msp430 -no problems
    On Aduc I tried to work with max3232 and max232 (he accepts 5V logic) - the same problem
    I can't open my COM1 port on correct baud.

Reply
  • Hi there
    Sorry for code:/ It's my first time in here.

    so, code from KEIL is:

    /*
     *  IODEMO.C:  Demonstrates usage of printf, scanf and malloc with
     *             GNU Compiler (on ADuC7024)
     *  Copyright KEIL ELEKTRONIK GmbH and KEIL SOFTWARE, Inc. 2003 - 2004
     *
     *  This file may be compiled in ARM or Thumb Mode
     */
    
    
    #include <ADuC7024.H>
    #include <stdio.h>
    #include <stdlib.h>
    
    unsigned char memory_pool[0x400];
    
    int main (void) {
            int iIterator;
            int iUserVar1 = 0;
            int *iArray;
    
            GP1CON = 0x011;                                                 // Setup tx & rx pins on P1.0 and P1.1
                                                                                            // Start setting up UART at 9600bps
            COMCON0 = 0x80;                                                 // Setting DLAB
            COMDIV0 = 0x93;
            COMDIV1 = 0x00;
            COMCON0 = 0x07;                                                 // Clearing DLAB
    
    // initialize memory pool
       init_mempool (memory_pool, sizeof(memory_pool));
    
    // create an array big enough to hold 10 integers
            iArray = malloc (10*sizeof(int));
    
            if(iArray == NULL)      {
                    printf("Malloc failed!\n");
            }
            else {
              for(iIterator = 0; iIterator<10; iIterator++) {
                    iArray[iIterator] = iIterator*2;
              }
            }
    
    // demonstrate user input via scanf
    // an alternative to scanf is gets and sscanf
            printf("please enter a number: ");
            scanf("%i", &iUserVar1);
            printf("\nUser Input: %i\n", iUserVar1);
    
        while (1);
    }
    
    
    
    
    /***********************************************************************/
    /*                                                                     */
    /*  SERIAL.C:  Low Level Serial Routines                               */
    /*                                                                     */
    /***********************************************************************/
    
    #include <ADuC7024.H>                      /* ADuC7024 definitions          */
    
    #define CR     0x0D
    //int putchar(int ch)  __attribute__ ((used));
    //int getchar (void)  __attribute__ ((used));
    
    int putchar(int ch){                   /* Write character to Serial Port  */
    
            if (ch == '\n')  {
            while(!(0x020==(COMSTA0 & 0x020)))
            {}
                    COMTX = CR;                                                     /* output CR */
                    }
        while(!(0x020==(COMSTA0 & 0x020)))
        {}
    
            return (COMTX = ch);
    }
    
    
    int _getkey (void)  {                      /* Read character from Serial Port */
    
            while(!(0x01==(COMSTA0 & 0x01)))
            {}
            return (COMTX);
    }
    
    
    
    
    /***********************************************************************/
    /*                                                                     */
    /*  SYSCALLS.C:  System Calls Remapping                                */
    /*                                                                     */
    /***********************************************************************/
    
    #include <stdlib.h>
    
    
    extern int putchar (int ch);
    extern int getchar (void);
    
    int read (int file, char * ptr, int len) {
      char c;
      int  i;
    
      for (i = 0; i < len; i++) {
        c = getchar();
        if (c == 0x0D) break;
        *ptr++ = c;
        putchar(c);
      }
      return len - i;
    }
    
    /*      Write a buffer using putchar function in serial.c       */
    
    int write (int file, char * ptr, int len) {
      int i;
    
      for (i = 0; i < len; i++) putchar (*ptr++);
      return len;
    }
    
    int isatty (int fd) {
      return 1;
    }
    
    
    void _exit (int n) {
    label:  goto label; /* endless loop */
    }
    
    
    #define HEAP_START 0x10000000
    #define HEAP_LIMIT 0x10010000
    
    caddr_t sbrk (int incr) {
    //extern char   end asm ("end");      /* Defined by the linker */
      static char * heap_end;
             char * prev_heap_end;
    
      if (heap_end == NULL) heap_end = (char *)HEAP_START;//&end;
      prev_heap_end = heap_end;
    
      if (heap_end + incr >= (char *)HEAP_LIMIT) {
        abort ();      /* Out of Memory */
      }
      heap_end += incr;
    
      return (caddr_t) prev_heap_end;
    }
    
    
    

    according to your post:
    1.On different baud hyperterminal doesn't get real information , he gets trash .
    For example I send "hello",and he gets "ee"
    It's posible when he can't find the speed of data,
    exactly he gets broken characters-but its not the point of my problem!
    2.there isn't another program using my port ,I'm programing my Aduc7026 by UART(the same port COM1)with max3232 , then I disconnect my programmer software (ARMWSD software), and turn on Hyperterminal
    3.Bad information is now I don't have an oscilloscope.
    4.This case is quite unnormal for me, I'm not beginner, When I set the required parameters for
    transmission 9600/no parity/2bis he displays that:I can't open my COM1 port, but when I set incorrect
    parameters like 4800/no parity/2bis he gets broken characters-so he is transmitting something!
    I read datasheet and analysed the code, every thing
    is ok and there's no way to move this UART on correct param.
    The same COM1 port is working normally with UART on LPC2146/at91sam/msp430 -no problems
    On Aduc I tried to work with max3232 and max232 (he accepts 5V logic) - the same problem
    I can't open my COM1 port on correct baud.

Children