Skip to content

Commit b1cedbc

Browse files
committed
Corrigindo erro na leitura da UART
1 parent 359344b commit b1cedbc

4 files changed

Lines changed: 18 additions & 20 deletions

File tree

modules/uart.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ always_ff @(posedge clk ) begin
6767
IDLE: begin
6868
counter_read <= 3'b000;
6969
if(read) begin
70+
read_data <= 32'h00000000;
7071
state_read <= READ;
7172
end else begin
7273
state_read <= IDLE;
@@ -92,7 +93,6 @@ always_ff @(posedge clk ) begin
9293
end
9394

9495
WB: begin
95-
read_response <= 1'b1;
9696
state_read <= FINISH;
9797
end
9898

rtl/interpreter.sv

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ always @(posedge clk) begin
146146
communication_read <= 1'b1;
147147
communication_buffer <= communication_read_data;
148148

149-
if(!communication_read_response) begin
149+
if(communication_read_response) begin
150150
state <= DECODE;
151151
end else begin
152152
state <= FETCH;
@@ -240,7 +240,7 @@ always @(posedge clk) begin
240240
communication_read <= 1'b1;
241241
communication_buffer <= communication_read_data;
242242

243-
if(!communication_read_response) begin
243+
if(communication_read_response) begin
244244
state <= SAVE_SECOND_WORD_IN_MEMORY;
245245
end else begin
246246
state <= READ_SECOND_PAGE_FROM_SERIAL;
@@ -364,7 +364,7 @@ always @(posedge clk) begin
364364
communication_read <= 1'b1;
365365
communication_buffer <= communication_read_data;
366366

367-
if(!communication_read_response) begin
367+
if(communication_read_response) begin
368368
state <= SAVE_WORD;
369369
end else begin
370370
state <= READ_WORD_FROM_SERIAL;

testbenchs/controller_tb.sv

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
module controller_tb();
44

55
logic clk, rx, rst_n, tx;
6+
logic [7:0] tx_data;
7+
logic tx_en;
8+
logic tx_busy;
9+
logic [7:0] tx_data_memory [0:16];
10+
logic [4:0] pointer;
611

712
initial begin
813
$dumpfile("build/controller.vcd");
@@ -12,7 +17,7 @@ initial begin
1217

1318
#20 rst_n = 1;
1419

15-
#3000;
20+
#12000;
1621

1722
$finish;
1823
end
@@ -21,7 +26,7 @@ logic [7:0] uart_rx_data;
2126

2227
always #1 clk = ~clk;
2328

24-
parameter BIT_RATE = 115200;
29+
parameter BIT_RATE = 4000000;
2530
parameter PAYLOAD_BITS = 8;
2631
parameter CLK_FREQ = 50000000;
2732

@@ -52,14 +57,10 @@ uart_tx #(
5257
.uart_tx_data (tx_data)
5358
);
5459

55-
logic [7:0] tx_data;
56-
logic tx_en;
57-
logic tx_busy;
58-
5960

6061
Controller #(
6162
.CLK_FREQ (50000000),
62-
.BIT_RATE (115200),
63+
.BIT_RATE (BIT_RATE),
6364
.PAYLOAD_BITS (8),
6465
.BUFFER_SIZE (8),
6566
.PULSE_CONTROL_BITS (32),
@@ -102,9 +103,6 @@ Controller #(
102103
);
103104

104105

105-
logic [7:0] tx_data_memory [0:16];
106-
logic [3:0] pointer;
107-
108106
initial begin
109107
tx_data_memory[0] = 8'h00;
110108
tx_data_memory[1] = 8'h00;
@@ -126,14 +124,14 @@ end
126124

127125

128126
always_ff @( posedge clk ) begin : TX_DATA_SEND
129-
if (rst_n) begin
127+
if (!rst_n) begin
130128
tx_data <= 8'h00;
131129
pointer <= 0;
132130
end else begin
133-
if (!tx_busy && ~(&pointer)) begin
134-
tx_data <= tx_data_memory[pointer];
135-
pointer <= pointer + 1;
136-
tx_en <= 1'b1;
131+
if (!tx_busy && !pointer[4] && !tx_en) begin
132+
tx_data <= tx_data_memory[pointer];
133+
pointer <= pointer + 1;
134+
tx_en <= 1'b1;
137135
end else begin
138136
tx_en <= 1'b0;
139137
end

0 commit comments

Comments
 (0)