BitFlow

UART Receiver (8N1) with Parity

advanced · state_machine · 260 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

UART Receiver (8N1) with Parity Implement a UART receiver that decodes asynchronous serial data. This is one of the most common HDL design exercises and appears in every embedded systems interview. **UART Frame (8 data bits, odd parity, 1 stop bit — often written 8O1):** ``` START (0) — always 0 8 data bits (sampled at baud rate) PARITY bit (odd parity) STOP (1) — always 1 ``` **Interface** | Port | Direction | Width | Description | |------------|-----------|-------|--------------------------------| | `clk` | input | 1 | System clock | | `rst` | input | 1 | Sync reset | | `rx` | input | 1 | Serial RX line (asynchronous) | | `baud_div` | input | 16 | Baud rate divider = clk/(baud) | | `data` | output | 8 | Decoded byte | | `valid` | output | 1 | 1-cycle pulse on valid frame | | `parity_err`| output | 1 | Parity error pulse | | `frame_err`| output | 1 | Framing error (stop bit = 0) | **FSM Behaviour** 1. **IDLE:** Wait for START bit (rx=0, sample at next baud clock) 2. **WAIT_HALF:** Wait half a baud period to centre-sample the start bit (avoid edge jitter) 3. **DATA:** Sample 8 data bits at baud intervals (shifted LSB-first) 4. **PARITY:** Sample parity bit; check odd parity across all data+parity bits 5. **STOP:** Sample stop bit (must be 1) 6. **VALIDATE:** Assert `valid`, `parity_err`, or `frame_err` for 1 cycle; return to IDLE **Timing:** Use a prescaler counter. When `counter == baud_div`, strobe a "baud clock" and reset counter. **Error handling:** - Parity error: XOR of (data[7:0] | parity_bit) ≠ 1 - Frame error: stop bit ≠ 1 - Both return to IDLE; only one error flag asserts per frame

Constraints

  • Implement a baud rate counter: increment on every system clock, reset when equal to baud_div.
  • Sample rx at baud clock edges.
  • Wait 0.5 baud periods after detecting START before sampling (centre-sample the bit).
  • Shift data LSB-first.
  • Verify odd parity: XOR(data[7:0], parity_bit) == 1.

Examples

Input: baud_div=10, rx drops to 0, stays low for ~5 clocks, then data bits

Output: After 11 bits + parity + stop, valid asserts with decoded byte

Normal frame

Input: stop bit = 0 (framing error)

Output: frame_err pulse, data discarded

Framing error

Input: parity bits don't match (even parity detected)

Output: parity_err pulse

Parity error

Common questions

What does the UART Receiver (8N1) with Parity problem ask you to build?
UART Receiver (8N1) with Parity Implement a UART receiver that decodes asynchronous serial data. This is one of the most common HDL design exercises and appears in every embedded systems interview.
What constraints does UART Receiver (8N1) with Parity have?
Implement a baud rate counter: increment on every system clock, reset when equal to baud_div.; Sample rx at baud clock edges.; Wait 0.5 baud periods after detecting START before sampling (centre-sample the bit).; Shift data LSB-first.; Verify odd parity: XOR(data[7:0], parity_bit) == 1.
What is an example input and output for UART Receiver (8N1) with Parity?
Input baud_div=10, rx drops to 0, stays low for ~5 clocks, then data bits gives output After 11 bits + parity + stop, valid asserts with decoded byte. Normal frame
Which Verilog concepts does UART Receiver (8N1) with Parity practise?
state_machine, UART, serial, interview, protocol.