Given the UART transmitter code below, what is the output tx signal sequence for sending the byte 0x55 (binary 01010101) with 1 start bit, 8 data bits, no parity, and 1 stop bit?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity uart_tx is Port ( clk : in STD_LOGIC; tx_start : in STD_LOGIC; tx_data : in STD_LOGIC_VECTOR (7 downto 0); tx : out STD_LOGIC; tx_busy : out STD_LOGIC); end uart_tx; architecture Behavioral of uart_tx is type state_type is (idle, start_bit, data_bits, stop_bit); signal state : state_type := idle; signal bit_cnt : integer range 0 to 7 := 0; signal shift_reg : STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); begin process(clk) begin if rising_edge(clk) then case state is when idle => tx <= '1'; tx_busy <= '0'; if tx_start = '1' then shift_reg <= tx_data; state <= start_bit; tx_busy <= '1'; end if; when start_bit => tx <= '0'; state <= data_bits; bit_cnt <= 0; when data_bits => tx <= shift_reg(bit_cnt); if bit_cnt = 7 then state <= stop_bit; else bit_cnt <= bit_cnt + 1; end if; when stop_bit => tx <= '1'; state <= idle; tx_busy <= '0'; end case; end if; end process; end Behavioral;
Remember UART sends the start bit as 0, then data bits least significant bit first, then stop bit as 1.
The UART transmitter sends a 0 start bit, then the data bits from LSB to MSB. For 0x55 (binary 01010101), the bits sent are 1,0,1,0,1,0,1,0 LSB first. Finally, it sends a 1 stop bit.
Consider the UART receiver code snippet below. After receiving the byte 0xA3 (binary 10100011) with 1 start bit, 8 data bits, no parity, and 1 stop bit, what will be the value of rx_data?
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity uart_rx is Port ( clk : in STD_LOGIC; rx : in STD_LOGIC; rx_data : out STD_LOGIC_VECTOR (7 downto 0); rx_ready : out STD_LOGIC); end uart_rx; architecture Behavioral of uart_rx is type state_type is (idle, start_bit, data_bits, stop_bit); signal state : state_type := idle; signal bit_cnt : integer range 0 to 7 := 0; signal shift_reg : STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); begin process(clk) begin if rising_edge(clk) then case state is when idle => rx_ready <= '0'; if rx = '0' then state <= start_bit; end if; when start_bit => if rx = '0' then state <= data_bits; bit_cnt <= 0; else state <= idle; end if; when data_bits => shift_reg(bit_cnt) <= rx; if bit_cnt = 7 then state <= stop_bit; else bit_cnt <= bit_cnt + 1; end if; when stop_bit => if rx = '1' then rx_data <= shift_reg; rx_ready <= '1'; end if; state <= idle; end case; end if; end process; end Behavioral;
The receiver stores bits LSB first as they arrive after the start bit.
The UART receiver captures bits starting from the least significant bit. For 0xA3 (binary 10100011), the bits arrive as 1,1,0,0,0,1,0,1 LSB first, which matches 10100011 when stored in rx_data.
Examine the UART transmitter state machine code below. Which option correctly identifies the error causing the transmitter to never send the stop bit?
architecture Behavioral of uart_tx is type state_type is (idle, start_bit, data_bits, stop_bit); signal state : state_type := idle; signal bit_cnt : integer range 0 to 7 := 0; signal shift_reg : STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); begin process(clk) begin if rising_edge(clk) then case state is when idle => tx <= '1'; tx_busy <= '0'; if tx_start = '1' then shift_reg <= tx_data; state <= start_bit; tx_busy <= '1'; end if; when start_bit => tx <= '0'; state <= data_bits; bit_cnt <= 0; when data_bits => tx <= shift_reg(bit_cnt); if bit_cnt = 7 then state <= data_bits; -- Error here else bit_cnt <= bit_cnt + 1; end if; when stop_bit => tx <= '1'; state <= idle; tx_busy <= '0'; end case; end if; end process; end Behavioral;
Check the transition after sending the last data bit.
The transmitter stays in data_bits state after sending the last bit because the code sets state <= data_bits; instead of state <= stop_bit;. This prevents sending the stop bit.
Which option contains the syntax error that will cause the UART receiver code below to fail compilation?
architecture Behavioral of uart_rx is type state_type is (idle, start_bit, data_bits, stop_bit); signal state : state_type := idle; signal bit_cnt : integer range 0 to 7 := 0; signal shift_reg : STD_LOGIC_VECTOR(7 downto 0) := (others => '0'); begin process(clk) begin if rising_edge(clk) then case state is when idle => rx_ready <= '0'; if rx = '0' then state <= start_bit; end if; when start_bit => if rx = '0' then state <= data_bits; bit_cnt <= 0; else state <= idle; end if; when data_bits => shift_reg(bit_cnt) <= rx; if bit_cnt = 7 then state <= stop_bit; else bit_cnt <= bit_cnt + 1; end if; when stop_bit => if rx = '1' then rx_data <= shift_reg; rx_ready <= '1'; end if; state <= idle; end case; end if; end process; end Behavioral;
Look carefully at each line ending in the idle state.
In VHDL, each statement must end with a semicolon. The line state <= start_bit in the idle state is missing a semicolon, causing a syntax error.
You have a UART transmitter and receiver both running at 9600 baud with 1 start bit, 8 data bits, no parity, and 1 stop bit. If the transmitter sends a continuous stream of bytes without delay, what is the minimum time interval between the start of one byte transmission and the start of the next byte reception at the receiver?
Calculate the time for one full UART frame (start + 8 data + stop bits) at 9600 baud.
At 9600 baud, each bit takes about 1/9600 โ 104.17 microseconds. One UART frame has 1 start + 8 data + 1 stop = 10 bits. So total time per byte is 10 ร 104.17 ยตs โ 1.04 ms. This is the minimum interval between start bits of consecutive bytes.
