Asynchronous in protocol - Page 1
Forum section: electronics / general

author: Kittu20
author_rank: Regular Contributor
timestamp: January 22, 2024, 12:48:29 pm
content: Hi everyone,I'm trying to understand what it means by asynchronous in protocols. I understand that I2C and SPI are synchronous, meaning the receiver knows when to read data based on the clock signal. However, UART is asynchronous. How does recover know when to read dataCould someone explain on what exactly is meant by asynchronous in this context?Thanks!

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 22, 2024, 01:02:41 pm
content: You already said it yourself. The synchronous ones use a clock signal to let the other side know when to read or write the data.In the asynchronous systems there is no clear clock signal and it has to be retrieved from the data. For this line signals are used. In case of the UART there is a start and a stop bit clearly marking the data. Also normally there is an agreement between both sides what bit rate is used. When the receiver sees a start bit it makes sure to align the internal clock such that it samples in the middle of the data bits.A lot of the UART peripherals use oversampling techniques to make this work reliable.

author: Andy Chee
author_rank: Super Contributor
timestamp: January 22, 2024, 01:13:58 pm
content: Asycnhronous means the transmitter clock and receiver clock are not synchronised.For example, for a theoretical 9600 baud rate transmission, the transmitter clock might be 9605.01 baud and the receiver clock might be 9598.94 baud. The differences are due to imperfect crystal oscillators in the transmitter and receiver.For the most common 1 start bit, 8 data bits, 1 stop bit, serial data format, you can tolerate maybe 2% baud rate difference before communication is impossible.

author: brucehoult
author_rank: Super Contributor
timestamp: January 22, 2024, 01:29:22 pm
content: Quote from: Andy Chee on January 22, 2024, 01:13:58 pmIt seems to me that if you're going to re-synchronise after every 10 bits then a 5% difference between sender and receiver should (just) work.

author: pcprogrammer
author_rank: Super Contributor
timestamp: January 22, 2024, 01:42:15 pm
content: I seem to remember from back in the 8051 days that depending on the xtal frequency and the divider setting specific baud rates could be made with a certain amount of error and still work reliably with other systems with different xtal frequencies, but I can't recall the absolute error with which it still worked.Here is an article about ithttps://www.allaboutcircuits.com/technical-articles/the-uart-baud-rate-clock-how-accurate-does-it-need-to-be/

author: dietert1
author_rank: Super Contributor
timestamp: January 22, 2024, 01:48:54 pm
content: Quote from: Andy Chee on January 22, 2024, 01:13:58 pmAs a first remark: In asynchronous communication the receiver uses its own clock to sample the incoming data. Making sense of those data depends on prior agreements on the data format.In synchronous communication the receiver gets and uses the transmitter clock to sample the incoming data.Regards, Dieter

author: coppice
author_rank: Super Contributor
timestamp: January 22, 2024, 01:58:22 pm
content: Quote from: brucehoult on January 22, 2024, 01:29:22 pmThe error you can tolerate varies a lot with the nature of the transmission and receiver sides. Quite a few sources do not have an accurate 1:1 mark:space ratio. A lot of low speed modems (V.21, V.,23. Bell 103) are like this. If the receiver is using a x16 clock to sample the incoming signal, which is the commonest form of UART, that gives you a 6.25% ambiguity in catching the edges. So now other factors can't add up to too much, or the last couple of bits of each byte will get pretty flaky. 2% is usually about the most mismatch you can tolerate between the source and sink side clocks. There are UART communication channels which can tolerate >8% without error, but there are unusual designs.

author: woofy
author_rank: Frequent Contributor
timestamp: January 22, 2024, 02:41:14 pm
content: On a 10bit frame (start + 8 data + stop) the leading trailing edge of the last bit is 5% away from the center of the bit. You have to stay inside of that. If if the Tx is 5% low and the Rx 5% high then it will not work. In practice 2% is a sensible max error. Some Microchip PIC's have a gotcha here. They will quote a headline 1% accuracy on the internal osc, but look closer and its actually 2% at best and 5% at temperature extremes (PIC18F24Q10). For that reason if I need UARTs then I put a crystal on the MCU and forget about it..

author: brucehoult
author_rank: Super Contributor
timestamp: January 23, 2024, 12:04:03 am
content: Quote from: woofy on January 22, 2024, 02:41:14 pmI agree with that.The person I was replying to said a 2% difference between tx and rx, not opposite 2% errors in each one.

author: coppice
author_rank: Super Contributor
timestamp: January 23, 2024, 02:20:24 pm
content: Quote from: woofy on January 22, 2024, 02:41:14 pmA lot of serial comms with PCs used to have a systemic error, which I think was over 1%. Some IC maker figured that dividing an available clock by a simple ratio got them pretty close to the normal UART bit rate sequence - 300, 600... 115200 - and it was good enough. I can't remember which clock they used, and the exact error they ended up with, but that was a very widely used design. I think that was an ISA specific issue, but in the 1990s it was pretty much the norm.

author: hans
author_rank: Super Contributor
timestamp: January 23, 2024, 07:05:33 pm
content: Quote from: Kittu20 on January 22, 2024, 12:48:29 pmBoth ends need to be in agreement on the baud rate set. Then, the receiver just need to knowwhento start sampling. This process is called synchronization. Or in more analog terms: the baud rate sets the frequency, and then synchronization locks in the phase.The frequency is "by design" (or needs to be set by user), while the phase needs to be resolved in the hardware during "runtime"Many protocolsonlylock in the phase at the start of a frame. For UART this is done by the start bit. The receiver knows (expects) a certain shape of an UART frame, and its statemachine can then decide when to sample the line. However, the exact implementation details can vary per UART.. for example, you could make a functional UART by sampling exactly in the middle of the (presumed) bit period, however, many UARTs use oversampling with e.g. majority vote.But because the UART only synchronizes its statemachine at the start bit, any frequency error will accumulate over time and hence there are some tolerances on the frequency errors (of both sides). More sophicated protocols are possible, on of which is UART "auto baud" mechanisms. These include sending aspecific characterwhich allows the start bit duration to be measured, so the UART receiver can "automatically" set up its timer registers accordingly. However, the characteristics of this "auto baud" training requires that the user protocol to include that, which is why I don't think its really used that often..Note that an UART uses a start bit for each individual character(frame) sent. This lowers the time window at which a correct sync is needed to only 10-10.5 bits or so, and hence, quite a poor oscillator tolerance could (theoretically) be supported. Again, may vary per implementation, though.However if you look at other asynchronous protocols such as CAN, USB HS or RF comms you'll find much stricter oscillator requirements. Some protocols that need to support sending very large frames also have more techniques to maintain synchronization, such as tricks with line encoding (think differential manchester) or using DLLs, PLLs or timing error detectors (popular for SDR).

author: ejeffrey
author_rank: Super Contributor
timestamp: January 23, 2024, 08:14:21 pm
content: Quote from: coppice on January 23, 2024, 02:20:24 pmIt still an issue with microcontrollers today. If you have a microcontroller with a 42 MHz bus clock, and 16x oversampling, the closest you can get to 115200 is something like 114100, about 1% low. Talk to someone else with a clock that works out a bit too high and you can eat up a significant margin of your clock tolerance before you even get started.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: January 24, 2024, 02:08:03 am
content: Quote from: coppice on January 23, 2024, 02:20:24 pmThe original PCs used 8250 UART and 1.8432MHz crystals, so they were very precise on bit-timing.When first USB-UARTS came along with the retiring of 'classic serial ports' on PCs they used 6/12MHz crystals for USB, and those baud speeds became 'exactly incorrect' and 115200 is 115384.6154- but at least 'two the same', would match.Then vendors got better at on chip oscillators, and using the trim in those oscillators to lock to the USB frame.The newest FS-USB-UARTS now have relaxed clock specs, as they use crystal-less digital locked loops, so those have errors of up to 0.5%, typically ~0.3%.

author: brucehoult
author_rank: Super Contributor
timestamp: January 24, 2024, 05:30:06 am
content: Quote from: PCB.Wiz on January 24, 2024, 02:08:03 amWhich is 0.16% error, which is perfectly fine.QuoteWhich is more error.

author: coppice
author_rank: Super Contributor
timestamp: January 24, 2024, 02:35:48 pm
content: Quote from: PCB.Wiz on January 24, 2024, 02:08:03 amThe very original PCs used 8250 chips and then 16450 chips. Then people like Chips and Technologies made optimised chip sets for PC motherboards, and people made 16450 workalikes for peripheral cards. If you look through those things you will find some interesting shortcuts. One made UARTs run quite a bit off the right frequency. More than the errors you get with USB UARTs. If you try the UART in the ITE chips on many modern motherboards you might find they still use whatever that shortcut was.