In this lesson, you will learn how to configure the specific hardware register settings that determine how your UART peripheral packages raw data into a valid transmission frame.
Since UART is an asynchronous protocol, the receiver has no shared clock to know when a bit starts or ends. To communicate reliably, both the transmitter and receiver must agree on the exact "shape" of the data packet. This is achieved by configuring the control registers of the UART peripheral to define three primary parameters: Data Word Length, Parity, and Stop Bits.
Data Word Length
This defines the number of bits in a single character, typically 8 bits. Some legacy systems use 7, while others might use 9 for specific addressing modes. Setting this in the hardware register tells the UART shift register how many times it must toggle the data line before the frame is considered "full."
Parity Bit Generation
Parity is a simple error-detection mechanism. When enabled, the hardware automatically calculates the number of high bits in your data word and adds one extra bit to make the total count either even or odd. If the receiver calculates a different parity than the one received, it triggers an error flag.
Stop Bit Duration
The stop bit signals the end of a frame and returns the line to the idle state (logic high). You can configure the hardware to hold this state for 1 or 2 bit periods. A longer stop bit provides a "breathing room" for the receiver's hardware to finalize processing the byte before the next start bit arrives.
Example Configuration If you wanted to configure a frame for 8 data bits, even parity, and 1 stop bit (8E1), your initialization code might look like this:
// Pseudocode for setting frame parameters in a control register
UART_CTRL_REG = (DATA_8_BITS << WORD_LEN_POS) |
(PARITY_EVEN << PARITY_POS) |
(STOP_BIT_1 << STOP_BIT_POS);
By ensuring these register bits match on both ends, you guarantee that the receiver correctly interprets the voltage transitions as meaningful data rather than random noise.
Key Takeaway: UART frame parameters establish the structural blueprint of the transmitted signal; if the transmitter's word length, parity, and stop bits do not perfectly align with the receiver's register settings, communication will result in persistent framing errors.