[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Small program for UART not working

From: Ian Caddy
Subject: Re: [avr-gcc-list] Small program for UART not working
Date: Mon, 29 Aug 2005 09:45:23 +0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20041206 Thunderbird/1.0 Mnenhy/

Hi Gary,

From your description of your output data, it looks like it is configured for either 7 data bits (which will cause the stop bit to look like the MSB of the data on the receiver causing it to be set), or that somehow parity is being set.

I had a quick look at your program and that doesn't seem to be the case, but have you made sure that you don't have your chip in mega103 compatability mode which does change the function of the UART? It is one of the programming fuses that enables this functionality and it is shipped with it ON by default.

Sorry I couldn't be of more help.


Ian Caddy

Gary Bi wrote:
Hi David,

Thanks for the info. I downloaded Tera Term Pro and
installed it in my PC, it's a defenitely a better
terminal simulation. Unfortunately I got the same

My problem are:

1. Atmel128L has successfully sent out characters in
TX, but I can not receive it correctly in PC termimal.
When monitoring the TX pin in scope, I can see char
'B' has been sent out continuouly. /* UART Transmit Complete Interrupt Function */
When I short TX and RX pin together in Atmel STK
board, I can see the 'B' was displayed correctly
(demonstrated using LEDs, PIN7-0 is for Bit7-0).
/* UART Receive Complete Interrupt Function */
RxChar = inp(UDR0);
outp(RxChar, PORTB);
What I receivd in TTP teminal is 0xA2 instead of
character 'B' (0x42).

2. I did not set baud rate in the codes for Atmel, in
TTP, I will need to set the baud rate to 57600, 8-N-1
to get the RX working, so if I type 'C', I can see the
LEDs is demonstrated 'C' correctly. If the set the
baud rate to 9600, 115200, etc. I can not get the Rx
working. This is very strange.
So I have to comment out the two lines for baud:
    //outp(0x0, UBRR0H);
    //outp( (u08)UART_BAUD_SELECT, UBRR0L);

The MCU is running at 7.3728Mhz, I set the baud
parameter to 0x2F according to the datasheet.
#define UART_BAUD_SELECT 0x2F //9600 baud

There's typo in my previous email, what I want to say
is: I can see the character 'B' is sending out, I just
did not receive it correctly in PC.

3. Do you think it's possible it's related to a defect
MCU (ATMEGA128L)? I'm trying to buy a new MCU(order
ATMEGA128-16AI (16Mhz), but not sure if it will work
with 7.3728MHz crystal on STK or not.


#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/pgmspace.h>

#define outp(a,b) b=a
#define inp(a) a
typedef unsigned char  u08;
typedef unsigned short u16;
#define UART_BAUD_SELECT 0x2F //9600 baud

#define PRG_RDB( addr )   __LPM((unsigned
#define BV(bit) (1 << (bit))

/* UART global variables */

volatile u08   RxChar;
volatile int i = 0;

/* UART Transmit Complete Interrupt Function */

/* UART Receive Complete Interrupt Function */
    RxChar = inp(UDR0);
        outp(RxChar, PORTB);

void UART_Init(void)
    /* enable RxD/TxD and interrupts */

    /* set baud rate */
    //outp(0x0, UBRR0H);
    //outp( (u08)UART_BAUD_SELECT, UBRR0L);

        // Async. mode, 8N1
       UCSR0C =
    /* enable interrupts */

int main(void)
        outp(0xff, DDRB); //port B output
//      for(;;){
//      }
        return 0;

AVR-GCC-list mailing list

Ian Caddy
Goanna Technologies Pty Ltd
+61 8 9221 1860

reply via email to

[Prev in Thread] Current Thread [Next in Thread]