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: Gary Bi
Subject: Re: [avr-gcc-list] Small program for UART not working
Date: Mon, 29 Aug 2005 17:37:09 -0700 (PDT)

>From the scope, I can calculate the baud rate rough
number, for example, if setting it to 9600 in MCU, on
scope, it was around that range; setting to 57600, the
reading from scope will be around 57600, etc. But I
don't know the exacly reading, since there's no way to
read it, I can only calculate it though the measure of
waveform frequency. I also noticed the start bit
(1bit) and stop bit (bit) is correctly set in the
waveform.

Thanks,
Gary


--- Gary Bi <address@hidden> wrote:

> Hi David and Ian,
> 
> Thanks for the help. I checked the fuses for mega101
> mode, it did set to ON. I uncheck it in AVR studio
> and
> program it, but this did not make improvement to the
> issue.
> 
> I shorted the PIN2 and PIN3 at the end of cable (the
> end plugs to PC RS232), I still can see the data was
> received through the loopback, demonstrated through
> LEDs on STK board. The RS232 cable is good, since I
> short the other end, I can see the chars typed
> displayed on the termial.
> 
> I'm suspecting the baud rate was not set accurately
> in
> Atmega128L, so cause the reception of PC side is not
> synchronized. For example, if I set to 115200, but
> not
> accurate, the number could be set as 115000, so I
> have
> some errors in PC terminal.
> 
> I tried to calculate the baud rate on scope, I found
> I
> can't get a exactly number, I can only get an
> estimate. Do you know if there's way to set the baud
> rate accurately?
> 
> Thanks,
> Gary
> 
> 
> 
> 
> --- David Brown <address@hidden> wrote:
> 
> > 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)
> 
=== message truncated ===





reply via email to

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