]> rtime.felk.cvut.cz Git - fpga/uart.git/blob - tx.vhd
RX modul synchronization changed to falling edges.
[fpga/uart.git] / tx.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_arith.all;
4 use ieee.std_logic_unsigned.all;
5
6 --------------------------------------------------------------------------------
7 -- Output shift register
8 --
9 -- This entity can be used for generating of RS232 like output. Configuration is
10 -- hard wired as 8N1 (8 bits of data, no parity, 1 stop bit).
11 --
12 -- All operations (except for 'reset') are synchronous to 'clk' rising edges.
13 -- This clock signal also determines baud rate.
14 --
15 -- When 'ready' signal is high, next data vector can be written in by setting
16 -- 'we' signal.
17 --------------------------------------------------------------------------------
18
19 entity transmitter is
20   port (
21     clk    : in  std_logic;
22     reset  : in  std_logic;
23     data   : in  std_logic_vector (7 downto 0);
24     we     : in  std_logic;
25     ready  : out std_logic;
26     tx     : out std_logic
27   );
28 end transmitter;
29
30 --------------------------------------------------------------------------------
31
32 architecture behavioral of transmitter is
33   
34   -- Output shift register (containing also start and stop bit).
35   signal tx_shift_reg : std_logic_vector (9 downto 0);
36   -- Register parallel to the output shift register where '1' shows the last
37   -- bit of the frame ('1' is in the place of stop bit).
38   signal tx_flag      : std_logic_vector (9 downto 0);
39   -- Transmitting of new frame could be started with next clk.
40   signal tx_ready     : std_logic;
41
42 --------------------------------------------------------------------------------
43
44 begin
45
46   process (clk, reset)
47   begin
48     if (reset = '1') then
49       tx_shift_reg <= "1111111111";
50       tx_flag <= "0000000000";
51       tx_ready <= '1';
52       
53     elsif (rising_edge(clk)) then
54       if (we = '1') then
55         tx_shift_reg <= '1' & data & '0';
56         tx_flag <= "1000000000";
57         tx_ready <= '0';
58         
59       else
60         tx_shift_reg <= '1' & tx_shift_reg(9 downto 1);
61         tx_flag <= '0' & tx_flag(9 downto 1);
62         
63         if (tx_flag(1) = '1') then
64           tx_ready <= '1';
65         end if;
66         
67       end if;
68     end if;
69   end process;
70
71 --------------------------------------------------------------------------------
72
73   ready <= tx_ready;
74   
75   tx <= tx_shift_reg(0);
76   
77 end behavioral;
78