← All problems

UART Receiver

Medium · Sequential · SystemVerilog

A premium problem. Subscribe to open it in the editor, run the testbench and see where your design lands.

Design a UART receiver that deserializes the serial stream on rx.

A frame is a low start bit, DATA_BITS data bits LSB first, then a high stop bit; rx idles high. A bit period is ⌊ CLK_FREQ / BAUD_RATE ⌋ cycles (434 at the defaults).

While the receiver is idle, the first cycle with rx low starts a frame. Half a bit period later, rounded down, rx is sampled: if it is high the start was a glitch and the receiver is idle again; otherwise each following bit is sampled one bit period after the one before, first the data bits and then the stop bit.

If the stop bit is sampled high, rx_valid is high for one cycle, the cycle after that sample, with the received word on rx_data; if it is sampled low, frame_error is high for that cycle instead. While rx_valid is low, rx_data may take any value. Either way the receiver is idle again in that cycle, ready for the next start bit.

resetn is a synchronous, active-low reset; it clears rx_valid and frame_error and makes the receiver idle.

  • Serial interfaces
  • State machines

Open this challenge in the editor →