This article discusses whether the number of data bits in the UART protocol can be increased.
A standard UART frame typically contains eight data bits.
A standard UART data frame consists of the following components:
- 1 start bit (always logic 0)
- 5-9 data bits (user data)
- 0 or 1 optional parity bit (for simple error detection)
- 1 or 2 stop bits (always logic 1)
Historical Context
The UART protocol has a long history, dating back to the early teletype era, which explains its compatibility with ASCII encoding.
Standard ASCII Encoding: The original ASCII standard was a 7-bit character set (0-127) capable of representing all English letters, numbers, and control characters.
Early UART Configuration: Configurations often used 7 data bits plus 1 parity bit. This created an 8-bit frame (one byte), which could transmit a complete ASCII character while providing simple error detection via the parity bit.
Evolution: As computer systems widely adopted the 8-bit byte as the basic unit of storage, it became more natural and efficient to drop the parity bit and use 8 data bits to transmit a full byte directly.
Efficiency
Each UART frame includes necessary overhead bits: a start bit (always low), one or two stop bits (always high), and an optional parity bit.
For example, assuming one stop bit and one parity bit, transmitting 8 bits of data requires sending a total of 1 (start) + 8 (data) + 1 (parity) + 1 (stop) = 11 bits. The effective data ratio is 8/11, or approximately 73%.
Transmitting more data bits per frame could theoretically increase this efficiency.
Can the Frame Be Extended (e.g., to 16 or 160 bits)?
If one side of the communication (either transmitter or receiver) uses fixed hardware, such as a standard PC or MCU serial port peripheral, you must adhere to the standard protocol rules, as the hardware cannot be changed.
However, if both the transmitter and receiver are fully customizable, is it possible to include more data bits in a single frame?
The transmitter uses its local crystal oscillator to time the output bits according to the specified baud rate. The receiver uses its own local crystal to time the sampling of these incoming bits, aiming for the middle of each bit period.
The problem arises because the transmitter's and receiver's crystal oscillators are separate and will always have some frequency error. Over a short frame (like 8 data bits), this timing deviation is small, and the receiver can reliably sample the bits. However, with a longer data frame, these small timing errors accumulate. Eventually, the receiver's sampling point will drift too far from the center of a bit, potentially sampling at the wrong time (e.g., during a bit transition) or missing/double-counting bits, leading to communication errors.
Recommendation:
It is generally best to stick with the standard 8-bit data frame for reliable communication.
How Significant is Clock Deviation?
The deviation of a crystal oscillator refers to the maximum allowed difference between its actual output frequency and its nominal frequency. This is typically expressed in parts per million (ppm).
1 ppm = 1 part in 1,000,000
- For a 1 MHz clock, 1 ppm = 1 Hz deviation.
- For a 10 MHz clock, 1 ppm = 10 Hz deviation.
- For a 100 MHz clock, 1 ppm = 100 Hz deviation.
Example Analysis: Impact on UART Communication
UART communication is highly sensitive to clock deviation. The cumulative timing error between the two devices causes the sampling point to drift, eventually leading to bit errors.
As a rule of thumb, the total clock error in a UART system (transmitter error + receiver error) should typically be kept within 2% to 3% to ensure reliable communication.
Calculation
- Assume both devices use crystals with a 20 ppm tolerance.
- In the worst-case scenario, the total deviation is 20 ppm + 20 ppm = 40 ppm.
- The error for a single bit is 40 / 1,000,000 = 0.004%. This is negligible for one bit.
- However, this error accumulates. Across a 10-bit frame (1 start + 8 data + 1 stop), the cumulative error is 0.004% * 10 = 0.04%. This is well below the 3% safety threshold, making a total deviation of 40 ppm perfectly acceptable for standard UART communication.