[Top][All Lists]

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

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

From: Gary Bi
Subject: [avr-gcc-list] Small program for UART not working
Date: Sat, 27 Aug 2005 20:02:29 -0700 (PDT)

I have next small program trying to set the UART0 for
Atmega128L, it is interrupt driven, I connect Atmel
STK502 with a PC, I found Rx is working, when clicking
the key, for example, type 'A', I can see the LED is

LED7-off, LED6-off,
LED5-on,LED4-on,LED3-on,LED2-on,LED1-on, LED0-off
The corresponding ASCII value is: 0x41 ('A').

My trouble is that the TX is not working, I can see
some garbage character is keeping displayed in the
Hyper terminal Window, but when I turn off the STK
board, I noticed in the bottom, there are some 'B'
characters displayed. My intention is to display one
'A' character and followed many 'B's (display 'B'

My believe the default baud rate is 57600 and 8-N-1
for Atmega128L, because in my code, I did not set the
baud rate, but the hyper terminal side, I need to set
it as 57600, 8-N-1 (eight bit, no parity bit, 1 stop

I tried to monitoring the TX in oscilloscope, I
noticed, 'A' character is keeping sending out.

Here is the output in my hyter terminal: 


I tried setting different baud rate, it became worse,
I can not even see chars displayed in pc side and the
RX is even not working when tried other baud rate.

Does anyone see the similiar issue before?

Attached is the complete code.

Thanks in advance.


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

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

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

/* UART global variables */

volatile u08   RxChar;

/* 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
        return 0;

reply via email to

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