You will have to be more specific. What baud rate and crystal frequency ? At most 'normal' baud rates, ie the ones 115300 baud and below, and with reasonable crystal frequencies, say 4MHz and above, the speed error on a software UART should be well within tolerance ( certainly below 2% ). You could look in the relevant library to see how the software loops are done, and if they are likely to introduce errors.
Are you getting UART errors in a particular application ?
If you are getting UART errors, you might also consider that a software UART samples the line level only once per bit time, whereas a hardware UART samples the line 16 times, and chooses the most common value for the line level. This inherently means the hardware UART is less susceptible to line noise.
And while it is true that in principal you can get smaller speed errors using software UARTs, you should always remember that software UARTS consume much processor time and cycles, during which you cannot do anything else.
My personal opinion is that you should only use software UARTs for debugging tests, or other very infrequent use, or when no other possible hardware UART solution is available.
To avoid baud rate errors, choose a crystal frequency which is a multiple of 1.732 MHz, then all the standard baud rates are available with no error on a hardware UART.
↧