1 ------------------------------------------------------------------------------
3 ---- RS-232 simple Rx module ----
5 ---- http://www.opencores.org/ ----
8 ---- Implements a simple 8N1 rx module for RS-232. ----
14 ---- - Philippe Carton, philippe.carton2 libertysurf.fr ----
15 ---- - Juan Pablo Daniel Borgna, jpdborgna gmail.com ----
16 ---- - Salvador E. Tropea, salvador inti.gob.ar ----
18 ------------------------------------------------------------------------------
20 ---- Copyright (c) 2001-2003 Philippe Carton ----
21 ---- Copyright (c) 2005 Juan Pablo Daniel Borgna ----
22 ---- Copyright (c) 2005-2008 Salvador E. Tropea ----
23 ---- Copyright (c) 2005-2008 Instituto Nacional de TecnologĂa Industrial ----
25 ---- Distributed under the GPL license ----
27 ------------------------------------------------------------------------------
29 ---- Design unit: RxUnit(Behaviour) (Entity and architecture) ----
30 ---- File name: rx_unit.vhdl ----
32 ---- Limitations: None known ----
33 ---- Errors: None known ----
34 ---- Library: zpu ----
35 ---- Dependencies: IEEE.std_logic_1164 ----
36 ---- Target FPGA: Spartan ----
37 ---- Language: VHDL ----
38 ---- Wishbone: No ----
39 ---- Synthesis tools: Xilinx Release 9.2.03i - xst J.39 ----
40 ---- Simulation tools: GHDL [Sokcho edition] (0.2x) ----
41 ---- Text editor: SETEdit 0.5.x ----
43 ------------------------------------------------------------------------------
46 use IEEE.std_logic_1164.all;
50 clk_i : in std_logic; -- System clock signal
51 reset_i : in std_logic; -- Reset input (sync)
52 enable_i : in std_logic; -- Enable input (rate*4)
53 read_i : in std_logic; -- Received Byte Read
54 rxd_i : in std_logic; -- RS-232 data input
55 rxav_o : out std_logic; -- Byte available
56 datao_o : out std_logic_vector(7 downto 0)); -- Byte received
59 architecture Behaviour of RxUnit is
60 signal r_r : std_logic_vector(7 downto 0); -- Receive register
61 signal bavail_r : std_logic:='0'; -- Byte received
67 variable bitpos : integer range 0 to 10; -- Position of the bit in the frame
68 variable samplecnt : integer range 0 to 3; -- Count from 0 to 3 in each bit
70 if rising_edge(clk_i) then
82 if rxd_i='0' then -- Start Bit
86 when 10 => -- Stop Bit
87 bitpos:=0; -- next is idle
88 bavail_r <= '1'; -- Indicate byte received
89 datao_o <= r_r; -- Store received byte
91 if samplecnt=1 and bitpos>=2 then -- Sample RxD on 1
92 r_r(bitpos-2) <= rxd_i; -- Deserialisation
94 if samplecnt=3 then -- Increment BitPos on 3
101 samplecnt:=samplecnt+1;
103 end if; -- enable_i='1'
104 end if; -- reset_i='0'
105 end if; -- rising_edge(clk_i)
107 end architecture Behaviour;