0

Serial port baud rate problem, need help
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Serial port baud rate problem, need help

by weihong1988 on Wed Apr 22, 2009 11:52 am

Hi guys, now I have more problems with the AVR microcontroller. This time, the serial port doesn't send out proper characters to the FTDI chip. I am 100% sure that the problem lies with the AVR as I connected the AVR TX line to a serial port via a MAX232 chip for a test. And yes, I am sure I set it to 19200, 8N1. I suspect the baud rate generator is not generating correct RS232 timings or somehow there is a framing error.

Here is a sample of the last few characters from the terminal window. I suspect those 'J' are actually dashes '-', and I can see the CR and LF characters too.
Code: Select all | TOGGLE FULL SIZE
ZÖÊi¥JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJÖÊJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJÖÊ   


Playing with the options, such as 19200, 7E1 (7 data bits, even parity, one stop bit) gives me a roughly legible data stream, something like "qavebubble v1.0", but the serial stream is pretty much corrupted ie. 25% corrupted, nearly unfunctional.

It could be that the internal RC osc is not that accurate, but then I changed UBRRn register to 207, (2400bps at 8.0000Mhz), 8N1 and it still didn't work, the '-' showed up as 'J' like above.

I am currently out of any ideas to try, can an AVR guru point out some troubleshooting tips? Lastly, what does this mean?

Code: Select all | TOGGLE FULL SIZE
void uart_init(uint16_t brr) {
   UBRR0 = brr;                                              // Ok, understand this,
   UCSR0B = _BV(RXEN0) | _BV(TXEN0);            //But where does the values
   UCSR0C = _BV(USBS0) | (3<<UCSZ00);         //come from?????
   DDRD |= _BV(PD1);
   DDRD &= ~_BV(PD0);
}


EDIT: I can post a scope pic of the serial stream if anyone thinks it may be helpful.

P.S. It would be nice if the world sticks to PICs
weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Re: Serial port baud rate problem, need help

by oPossum on Wed Apr 22, 2009 1:30 pm

weihong1988 wrote:It could be that the internal RC osc is not that accurate


It isn't unless you calibrate it.
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Serial port baud rate problem, need help

by weihong1988 on Wed Apr 22, 2009 11:51 pm

oPossum wrote:It isn't unless you calibrate it.


Ok true, Atmel claims it is accurate to 2% at 8.0000MHz. Assuming the baud rate is 10-20% out at 19200bps, I have bummed down the baud rate down to 2400bps (dividing down the error by a factor of eight) and it is still not successful. So either the clock is incredibly screwed or that there is a framing error, extra start pulses etc, I am not too sure at the moment.
weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Re: Serial port baud rate problem, need help

by oPossum on Thu Apr 23, 2009 12:02 am

The error is the same at any bit rate.

If an 8 mHz clock is 5% fast, then dividing that clock by 3328 ((207+1)*16) will give a 2400 Hz clock that is 5% fast.

8,000,000 + 5% = 8,400,000

8,400,000 / 3328 = 2524

2524 / 2400 = 1.05 (== + 5%)
I am the Possum, and I approve of this message. Sent from MacBook Wheel Sorry for my bad German.
oPossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am
Location: Michigan, USA

Re: Serial port baud rate problem, need help

by weihong1988 on Fri Apr 24, 2009 10:06 am

Ok, did some more debugging today, and IT WORKS! Some scope work and assigning constants to the UCSRC and UCSRB register rewarded me with the test_uart() code working at 19200, 8N1, with the default baud rate value (25) listed in the atmel datasheet. Not really sure what was wrong though, but since it works I am going to leave the ugly magic numbers there.

But wait! there's more. Since the VCO and PLLs were already done, I added the cell phone frequencies, crossed my fingers and hit tune. The thing tuned right up on my first try, and I am rewarded with No Signal on my cell phone! Hooray! My wave bubble works like a charm, even with only some 1/4 wave wire antenna and no gain stage. All I have to do now is to bring to school to show off.

** Special tanks to neutered and oPossom for their "technical support" on this forum **
weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Re: Serial port baud rate problem, need help

by neutered on Fri Apr 24, 2009 5:16 pm

[quote="weihong1988"]Ok, did some more debugging today, and IT WORKS! Some scope work and assigning constants to the UCSRC and UCSRB register rewarded me with the test_uart() code working at 19200, 8N1, with the default baud rate value (25) listed in the atmel datasheet. Not really sure what was wrong though, but since it works I am going to leave the ugly magic numbers there.
[/quote]

cool!

when i was having this issue something was causing the internal clock to be consistently off (fast). i basically ended up doing what you were doing w/ a FIXME comment that i needed to figure out how to get the clock more consistent. i think that this is somewhat related to the 'issue' you mentioned a while back w/ the vco, but that is probably just my sw guy-ness talking.
neutered
 
Posts: 43
Joined: Wed Dec 03, 2008 3:21 pm

Please be positive and constructive with your questions and comments.