EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Baud 1200

Started by terry November 29, 2004
Hi,

I used ATMega16 UART to communicate with a target device which is of
baud 1200 but failed. I then tried to communicate the UART with PC COM
Port and terminal software. I found the communication is OK when the
baud is from 115200 down to 2400. But straight characters appear when
the baud rate turns to 1200.

My baud setting function is:

void uartSetBaudRate(u32 baudrate)
{
  u16 bauddiv=F_CPU/baudrate/16L-1;
  outb(UBRRL, bauddiv);
  outb(UBRRH, bauddiv>>8);
}

Do anyone has my similar problem? The MCU clock speed is 7.3728MHz. 

Thanks!
> void uartSetBaudRate(u32 baudrate) > { > u16 bauddiv=F_CPU/baudrate/16L-1; > outb(UBRRL, bauddiv); > outb(UBRRH, bauddiv>>8); > }
Isn't it the UBRRL write that triggers the change in the baudrategenerator so you should change the order of writing to UBRRH and UBRRL?
"terry" <leonlai2k@yahoo.com> wrote in message
news:9904d48.0411282334.649a890d@posting.google.com...
> Hi, > > I used ATMega16 UART to communicate with a target device which is of > baud 1200 but failed. I then tried to communicate the UART with PC COM > Port and terminal software. I found the communication is OK when the > baud is from 115200 down to 2400. But straight characters appear when > the baud rate turns to 1200. > > My baud setting function is: > > void uartSetBaudRate(u32 baudrate) > { > u16 bauddiv=F_CPU/baudrate/16L-1; > outb(UBRRL, bauddiv); > outb(UBRRH, bauddiv>>8); > } > > Do anyone has my similar problem? The MCU clock speed is 7.3728MHz. > > Thanks!
From the data sheet: "The UBRRH contains the four most significant bits, and the UBRRL contains the 8 least significant bits of the USART baud rate. Ongoing transmissions by the transmitter and receiver will be corruptedif the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate prescaler." i.e. UBBRL should be written second. Cheers, Alf
Have tried to write UBRRH firstly and then UBRRL secondly but still failed.:{
"terry" <leonlai2k@yahoo.com> wrote in message 
news:9904d48.0411290845.55960cb5@posting.google.com...
> Have tried to write UBRRH firstly and then UBRRL secondly but still > failed.:{
Check your oscillator frequency (with a counter), it might be slightly out. I vaguely remember from somewhere that this can be more important with low baud rates. Leon -- Leon Heller, G1HSM http://www.geocities.com/leon_heller http://www.kasamba.com/viewExpert.asp?conMemID=105725&Catid=1111&banID=2100
I have tried another sample but it still happens!
terry wrote:

> I have tried another sample but it still happens!
How about making it transmit continuously, putting a scope on the output, and looking at what's actually coming out? Continuous stream of 0x55s or 0xAAs should give something easily visible. And if nothing comes out, change the values you are putting in the Baud registers until something does, and work from there. Paul Burke

The 2024 Embedded Online Conference