Electronic – How do two UARTS know which baud rate to use

baudratereceivertransmitteruart

I am reading about the standard protocol for UART and I think that if the receiving UART does not have any idea on what baud rate the data was transmitted, there would be lots of problems. If the assumed baud rate is lower than the baud rate in which the data is transmitted, there will be bits that would not be 'seen' by the receiving UART. On the other hand if the baud rate used by the receiver is higher than than the baud rate in which the data is transmitted, there will be bits that will be counted twice and would result the data being 'read' incorrectly.

My knowledge around UART is that when the line is idle, it is kept to a '1', the Start bit is a '0' and the Stop bit is a '1'. Also, the Stop bit being '1' does not have any difference with the '1' when the line is idle or is there a way to differentiate?

Do two communicating UART's first agree on which baud rate they will use? If yes, how do they do it?

Best Answer

Ordinary UARTs have to be pre-configured with the desired baud rate (as well as word length, stop bits, parity, etc) traditionally by a human.

For several decades now though there have been implementations of "auto baud" detection found in some settings, which typically works by timing key features of the waveform to deduce the baud rate. Early versions needed a known character to be transmitted, but more sophisticated versions might be able to find the rate from more arbitrary data.

A receiving UART typically has a local clock that runs at a faster rate - typically 8 or 16 times the baud rate. This is used to sample the incoming signal and detect the bits within a word in a way that can tolerate a few percent of error. Even two crystal oscillators wouldn't match rates perfectly, but the error tolerance can permit use of some less precise sources, sometimes including trimmed on-chip oscillators, etc. It can also help accommodate the fact that dividing down popular oscillator frequencies may only produce an inaccurate approximation to certain baud rates - in the old days, UART master clocks sometimes needed particular frequencies to access popular baud rates, for example 11.0592 MHz on the 8051 family.