0
0
Embedded Cprogramming~10 mins

UART protocol fundamentals in Embedded C - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - UART protocol fundamentals
Idle Line
Start Bit Detected
Read Data Bits (usually 8)
Check Parity Bit (optional)
Read Stop Bit(s)
Frame Complete -> Data Ready
Back to Idle Line
UART communication starts with an idle line, detects a start bit, reads data bits, optional parity, stop bits, then completes the frame and returns to idle.
Execution Sample
Embedded C
void uart_receive() {
  if (start_bit_detected()) {
    uint8_t data = read_8_bits();
    if (check_parity(data)) {
      process_data(data);
    }
  }
}
This code waits for a start bit, reads 8 data bits, checks parity, and processes the data if parity is correct.
Execution Table
StepSignal DetectedActionData ValueStatus
1Idle line (high)Wait for start bit-Waiting
2Start bit (low)Start reading data bits-Start bit detected
3Data bit 0Read bit1Reading data
4Data bit 1Read bit0Reading data
5Data bit 2Read bit1Reading data
6Data bit 3Read bit1Reading data
7Data bit 4Read bit0Reading data
8Data bit 5Read bit0Reading data
9Data bit 6Read bit1Reading data
10Data bit 7Read bit0Reading data
11Parity bitCheck parity-Parity OK
12Stop bit (high)Frame complete0b01011001Data ready
13Idle lineWait for next start bit-Waiting
💡 Stop bit received and parity checked, frame complete, ready for next frame.
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6After Step 7After Step 8After Step 9After Step 10Final
data_bits-1101011011101101011001011001101100100b01011001
Key Moments - 3 Insights
Why does UART start with a low start bit instead of high?
The start bit is low to signal the beginning of data transmission clearly because the idle line is high; this contrast helps the receiver detect the start (see execution_table step 2).
What happens if parity check fails?
If parity fails, the data is considered corrupted and usually discarded or flagged; in the example, process_data() is only called if parity is OK (see execution_table step 11).
Why do we read data bits one by one instead of all at once?
UART sends bits serially over one wire, so the receiver reads each bit in sequence to reconstruct the byte (see variable_tracker showing bits accumulating step by step).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 5, what is the data_bits value after reading data bit 2?
A101
B10
C1
D0
💡 Hint
Check the 'Data Value' and 'Action' columns at step 5 in execution_table.
At which step does the UART frame become ready for processing?
AStep 11
BStep 12
CStep 10
DStep 13
💡 Hint
Look for 'Frame complete' and 'Data ready' status in execution_table.
If the parity bit was incorrect, what would change in the execution flow?
AData bits would be skipped
BStart bit would be ignored
Cprocess_data() would not be called
DStop bit would be read twice
💡 Hint
Refer to key_moments about parity check and execution_table step 11.
Concept Snapshot
UART sends data serially with:
- Idle line high
- Start bit low to begin
- 8 data bits sent one by one
- Optional parity bit for error check
- Stop bit(s) high to end frame
Receiver detects start, reads bits, checks parity, then processes data.
Full Transcript
UART protocol works by keeping the line idle high. When data is sent, a low start bit signals the beginning. Then 8 data bits are sent one after another. Optionally, a parity bit is sent to check errors. Finally, stop bit(s) high mark the end of the frame. The receiver watches the line, detects the start bit, reads each data bit in order, checks parity, and when the stop bit arrives, the data is ready to use. This step-by-step process ensures reliable serial communication.