One thing that nag me with async serial (e.g. async 9600-8N1 since I can't say RS232 and be correct ) is does async really mean completely async?
e.g. after a 10-bit frame (start bit, 8 bits data, stop bit), can the pause be a completely random period of time, or should it be an integer number of bit-times.
A really good question... one that is rarely addressed in tutorials.The inter-character delay (and inter-line delay) are strictly speaking, functions of how efficient the receiver is at unloading the character from the receiver's input shift-register.
Most
hardware UARTs provide at least one word of buffering - so the Rx queue can begin shifting another character while the processor is popping the previous 'completed' character out of the FIFO. Software UARTs (bit-bashing) may not be so accommodating - and incur additional CPU cycles.
With the performance of modern chips, it is reasonable to expect the CPU can be ready to pop a new completed character out of the receiver
within one word time (n x bit periods), unless the serial data rate is particularly fast. (e.g. 1 bit @ 115200 bps = 8uS)
In theory, only one idle bit duration is
needed between the end of the STOP bit and the beginning of the
next START bit. To get the best out of a serial handler - interrupt driven operation with simple FIFO/circular-buffers are the fastest way to handle longer serial data blocks reliably.
Interrupts (and ideally FMA) lets you move the received data from the UART buffer into RAM as needed - in the minimum time - freeing up the CPU to do other time sensitive stuff.
Using
delay(), wait() or other
blocking code is unhelpful when handling
any asynchronous events - as the recovery period between edges is determined by the delay - not the data stream.
If the receiving program is unable to ingest the most recent character before the next one is 'ready' - then you'll see buffer over-run flagged by the UART module.
(I the bit timing is too far off spec between the TX and RX UARTs (or the bit-bashing code stretches some bits irregularly) - you'll get a framing error.)