Serial port baud rate problem, need help

The operation of transmitters designed to jam or block wireless communications is a violation of the Communications Act of 1934, as amended ("Act"). See 47 U.S.C. Sections 301, 302a, 333. The Act prohibits any person from willfully or maliciously interfering with the radio communications of any station licensed or authorized under the Act or operated by the U.S. government. 47 U.S.C. Section 333. The manufacture, importation, sale or offer for sale, including advertising, of devices designed to block or jam wireless transmissions is prohibited. 47 U.S.C. Section 302a(b). Parties in violation of these provisions may be subject to the penalties set out in 47 U.S.C. Sections 501-510. Fines for a first offense can range as high as $11,000 for each violation or imprisonment for up to one year, and the device used may also be seized and forfeited to the U.S. government.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Serial port baud rate problem, need help

Post by weihong1988 »

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

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

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

User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

Re: Serial port baud rate problem, need help

Post by opossum »

weihong1988 wrote:It could be that the internal RC osc is not that accurate
It isn't unless you calibrate it.

weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Re: Serial port baud rate problem, need help

Post by weihong1988 »

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.

User avatar
opossum
 
Posts: 636
Joined: Fri Oct 26, 2007 12:42 am

Re: Serial port baud rate problem, need help

Post by opossum »

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%)

weihong1988
 
Posts: 9
Joined: Fri Oct 31, 2008 10:19 am

Re: Serial port baud rate problem, need help

Post by 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.

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 **

neutered
 
Posts: 43
Joined: Wed Dec 03, 2008 3:21 pm

Re: Serial port baud rate problem, need help

Post by neutered »

[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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wave Bubble”