avr-gcc-list
[Top][All Lists]
Advanced

[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
toggling: 

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'
forever).

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
bit).

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

Here is the output in my hyter terminal: 

¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢
¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢¢
¢¢¢¢¢ÂÂÂÂÂÂBBBBBBB

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.

Gary

-------------------------------------------
#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
short)(addr))
#define BV(bit) (1 << (bit))

/* UART global variables */

volatile u08   RxChar;

/* UART Transmit Complete Interrupt Function */
SIGNAL(SIG_UART0_TRANS)      
{

 outp('B',UDR0);
 
}

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

void UART_Init(void)
{
    /* enable RxD/TxD and interrupts */
   
   
outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
    /* set baud rate */
    //outp(0x0, UBRR0H);
    //outp( (u08)UART_BAUD_SELECT, UBRR0L);

        // Async. mode, 8N1
       UCSR0C =
(0<<UMSEL0)|(0<<UPM01)|(0<<UPM00)|(0<<USBS0)|(3<<UCSZ00)|(0<<UCPOL0);
    /* enable interrupts */
    sei();
}

int main(void)
{
        outp(0xff, DDRB); //port B output
        UART_Init();
    outp('A',UDR0);
        return 0;
}





reply via email to

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