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

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

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


From: David Brown
Subject: Re: [avr-gcc-list] Small program for UART not working
Date: Mon, 29 Aug 2005 11:30:22 +0200

Hi,

Since you can see the data on your scope, and loopback works fine when
shorting RX and TX pins, there seems to be nothing wrong with the
microcontroller.  The things I would now check are the baud rate (using the
scope), the RS-232 line drivers, the TX-RX orientation (I've fixed many
communications problems by swapping the TX and RX lines !), the cable
between the board and the PC (including the ground line), and the PC serial
port.  It can be worth shorting the TX and RX pins at the board end of the
cable and testing loop-back from the PC side using TTP.

mvh.,

David



> 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
> result.
>
> 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 */
> SIGNAL(SIG_UART0_TRANS){
> outp('B',UDR0);
> }
> 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 */
> SIGNAL(SIG_UART0_RECV){
> 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.
>
> Thanks,
> Gary
>
> ======================================================
> #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
> short)(addr))
> #define BV(bit) (1 << (bit))
>
> /* UART global variables */
>
> volatile u08   RxChar;
> volatile int i = 0;
>
> /* UART Transmit Complete Interrupt Function */
> SIGNAL(SIG_UART0_TRANS)
> {
>  outp(0x43,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);
>     //outp(BV(RXCIE0)|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();
> // for(;;){
>     outp(0x41,UDR0);
> // }
> return 0;
> }
>
>
>





reply via email to

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