3
\$\begingroup\$

I am a bit confused regarding the baud rate of serial communication.

Suppose I am sending a value of 198 to the receiver with a baud rate of 9600. At the receiver, the rate is also the same. Thus isn't it possible that the data is lost? This means that after 1/9600 s a data bit is sent, and at this time the data is received as well. This means at each edge we are receiving and data can be lost since edges are not that accurate. If we have the baud rate of the receiver a bit different so it takes the data a bit ahead from the edge then it will work fine. But we usually use the same. How doesn't it create a problem?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ OK; just to verify, when you say "serial" you mean "UART", right? If that's the case, please visit the wikipedia article on UART. It looks like you really didn't do much research into this. \$\endgroup\$ Jul 12 at 8:02
  • 3
    \$\begingroup\$ The receiver tries to sample the data "in the middle of the bit time". With a UART, there usually is a start bit and at least one stop bit. \$\endgroup\$
    – greybeard
    Jul 12 at 8:05
  • 1
    \$\begingroup\$ Please look up the term asynchronous communication. \$\endgroup\$
    – winny
    Jul 12 at 8:05
  • \$\begingroup\$ Probably not eligible as a duplicate question, but you may find this illuminating. electronics.stackexchange.com/questions/207870/… \$\endgroup\$ Jul 12 at 8:41

4 Answers 4

12
\$\begingroup\$

This means at each edge we are receiving and data can be lost since edges are not that accurate.

A UART (as I believe you are talking about) makes use of start and stop bits to acquire synchronization: -

enter image description here

And, the receiver operates an internal clock (usually 16 times higher than the baud rate to ensure that data is "captured" in the middle of each symbol. As soon as the receiver detects the falling edge of the start bit it counts 8 clocks to position itself in the middle of the start bit. Then, 16 clocks later it knows it's in the middle of the 1st bit etc..

Image from here.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Good answer. While you didn't say this explicitly, the key to this process working is that the receiver needs to have some idea what the bit/baud rate is, so that it can set it's 16x receive clock accordingly. \$\endgroup\$
    – SteveSh
    Jul 12 at 11:43
  • 1
    \$\begingroup\$ This is also the reason why UART transmissions are broken up into small words (usually 5-9 bits each), so that the start/stop synchronization happens regularly. If you tried to transmit f.ex. 1000 bit words then the chance of losing data to clock drift would be much higher. \$\endgroup\$
    – Frodyne
    Jul 13 at 8:02
  • \$\begingroup\$ When making UART receive logic in an FPGA, I often used 13x oversampling, because 115200 * 13 is 1.5 MHz. I've also seen some microcontrollers that allow switching the internal ratio between TX and RX between 13 and 16 (but I can't remember which ones right now) \$\endgroup\$
    – Ben Voigt
    Jul 13 at 15:04
5
\$\begingroup\$

I am a bit confused regarding the baud rate of serial communication.

Your confusion appears to be about the basic clock synchronisation, not the baud rate.

so it takes the data a bit ahead from the edge

Your thinking is along the right lines: how do we make sure the receiver isn't sampling near the edge of the bit time. But your suggestion about how to do this:

If we have the baud rate of the receiver a bit different

... that won't work in the way you're imagining. We don't want different rates, we want the reciever to estimate where the sender's bit times begin. To sample reliably, we can sample in the middle of where the receiver thinks the bit will be.

The correct way uses the falling edge of the start bit to achieve this synchronisation.

enter image description here

enter image description here

The green part ensures we're in idle or a stop bit; the blue part finds the falling edge (we want to do this quickly, perhaps 16 times as fast as the bit rate), and the red part estimates the middle of the bit time, followed by getting the bits.

All the sophistication lies in either a) Finding that falling edge accurately, b) multiple sampling in order to discount spurious spikes, or c) dealing with any errors.

It's not common, but you can make systems which measure the bit rate from the signal. More common is to detect which of the common speeds is in use by trying different them and looking for recognisable patterns such as ASCII CR values. But without a doubt the most common case is simply to have both sides configured to use the same speed.

\$\endgroup\$
4
\$\begingroup\$

No, it is genrally not possible to lose data under normal conditions, as the receiver actually runs faster than at the bit rate to be able to receive bits properly at the bit rate

For 10-bit frames, i.e. 8N1 format, UARTs in practice tolerates a baud rate difference of approximately 4%. In theory, sampling the last bit can have a drift of +/- half a bit from the center of the bit so the receiver could in theory run 5% slower or faster.

Which means that one device could be about 2% slower than 9600, and the other device about 2% faster than 9600 and they would communicate successfully.

Generally accepted values for baud rate tolerances of individual devices are smaller, in the 0.5% to 1% range from the nominally reported baud rate.

This is because a clock source used may have some tolerance, and it can't be directly divided into exact bit rate. For example it is not possible to divide a 8 MHz clock soure to exactly 9600, but within 0.17% of 9600 is possible.

The specific problem you seem to be thinking is solved by oversampling, as a typical UART uses 16x oversampling for each bit slot to detect the start bit edge and sample data bits at the center of the bit time slot.

\$\endgroup\$
1
\$\begingroup\$

This answer is based on the tags in the OP's post. The Atmega microcontroller series, including the Atmega128, has built-in UART (Universal Asynchronous Receiver-Transmitter) hardware for serial communication. The term "Asynchronous" (in digital communication) pertains to a transmission technique that does not require a common clock between the communicating devices; timing signals are derived from special characters (symbols) in the data stream itself. So because start and stop are recognized at the receiver end no data can be lost as the way you described.

\$\endgroup\$
3
  • \$\begingroup\$ @jonathanjo If you replace the word character with symbol, it will work. A bit is also a symbol and a character is a symbol. In every day language, the start bit is a special character in the data stream, inserted for synchronization. \$\endgroup\$
    – Justme
    Jul 12 at 10:11
  • \$\begingroup\$ @jonathanjo And regardless of symbol being correct term, even if you have 10-bit symbols made from 8-bit bytes, they can be called characters in standards. For example 8b10b has definitions for symbols that are control characters if they are not data characters. Merriam-Webster also defines character as symbol that represents information, among other definitions. \$\endgroup\$
    – Justme
    Jul 12 at 10:39
  • \$\begingroup\$ @jonathanjo The word "special character" here is used to represent a 10-bit grouping of which the first and last bits are derived as a timing signal. Both special character and symbol are used interchangeably in common IT jargon. Which is more correct I am not sure. \$\endgroup\$ Jul 12 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.