Keil Logo Arm Logo

Discussion Forum

UART examples for ADuc7026

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
tomasz wilko
Posted
30-Dec-2007 06:30 GMT
Toolset
ARM
New! 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

Read-Only
Author
Per Westermark
Posted
30-Dec-2007 06:43 GMT
Toolset
ARM
New! RE: UART examples for ADuc7026

You have a big problem with this forum too. Did you read the instructions about how to post source code? Your posted code is not readable!

The hyperterminal doesn't know about what you do in your program, so it should not be possible for it to accept 4800 baud but fail to open the serial port for 9600 baud. Did you have any other program using the same port and then stopped that second program?

If the program configures 9600 baud and you on the PC connects using 4800 baud, it is reasonable that you get broken characters.

1) Set hyperterminal to the correct baudrate.

2) Verify the baudrate of the connection with an oscilloscope.

3) If the problem persists: Repost your code, but this time according to the posting instructions!

Read-Only
Author
Per Westermark
Posted
30-Dec-2007 07:08 GMT
Toolset
ARM
New! RE: UART examples for ADuc7026

The normal reasons for failing to open the serial port is that it is already open by another program or that you have specified a missing port (such as com2 on a computer that only have com1 installed).

Read-Only
Author
tomasz wilko
Posted
30-Dec-2007 10:27 GMT
Toolset
ARM
New! RE: UART examples for ADuc7026

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.

Read-Only
Author
Per Westermark
Posted
31-Dec-2007 00:42 GMT
Toolset
ARM
New! RE: UART examples for ADuc7026

Drop Hyperterminal and get a better program. Have you tried TeraTerm?

Read-Only
Author
tomasz wilko
Posted
31-Dec-2007 01:43 GMT
Toolset
ARM
New! RE: UART examples for ADuc7026

Ok, I'll make that
But I solved the problem:) , I set the CD PLL multiplier
in Startup.s on 1 (001) -this is 28MHz clock , but it should be CD: 0 (000) - and this is 41MHz
my recommended frequency.
Thanks for every think

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.