-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSRT_Rx.v
73 lines (64 loc) · 1.17 KB
/
USRT_Rx.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module USRT_Rx(CLK,RST,SI,Rx_Byte, NINTI);
input CLK,RST, SI;
output reg [7:0] Rx_Byte;
output reg NINTI;
parameter IDLE = 3'b000;
parameter START_BIT = 3'b001;
parameter RECV_BIT = 3'b010;
parameter STOP_BIT = 3'b011;
reg [2:0]state = 0;
reg [2:0]Bit_Index = 0;
always @(posedge CLK)
begin
if (RST)
begin
state <= IDLE;
NINTI <= 1'b0;
end
else
begin
case (state)
IDLE: // IDLE
begin
if (SI==1'b0)
begin
NINTI <= 1'b1;
state <= START_BIT;
end
else
begin
NINTI <= 1'b1;
state <= IDLE;
end
end
START_BIT:
begin
NINTI <= 1'b0;
state <= RECV_BIT;
Rx_Byte[Bit_Index] <= SI; //First bit of Data reception
Bit_Index = Bit_Index + 1;
end
RECV_BIT:
begin
NINTI <= 1'b0;
Rx_Byte[Bit_Index] <= SI; //remaining 7 bit Data reception
if (Bit_Index < 7)
begin
Bit_Index = Bit_Index + 1;
state <= RECV_BIT;
end
else
begin
Bit_Index = 0;
state <= STOP_BIT;
end
end
STOP_BIT:
begin
NINTI <= 1'b1;
state <= IDLE;
end
endcase
end
end
endmodule