1
0
forked from tanchou/Verilog

Add DHT11 UART communication module and related components

- Implemented a FIFO buffer in Verilog for data storage.
- Created a simplified UART transmitter (txuartlite) for serial communication.
- Developed a UART transmission FIFO (uart_tx_fifo) to manage data flow.
- Designed the top-level module (dht11_uart_top) to interface with the DHT11 sensor and handle data transmission.
- Added a testbench (tb_dht11) for simulating the DHT11 module functionality.
- Updated README with project description and command references.
- Created build and simulation scripts for both Linux and Windows environments.
- Added constraints file for hardware configuration.
- Implemented a state machine for managing measurement and data transmission.
This commit is contained in:
2025-05-22 12:27:16 +02:00
parent a541e033d7
commit 54bf6df85b
22 changed files with 1259 additions and 34 deletions

View File

@@ -0,0 +1,97 @@
`default_nettype none
module dht11_uart_top (
input clk,
inout io_dht11_sig,
output tx
);
localparam CLK_FREQ = 27_000_000; // 27 MHz
reg [7:0] wr_data;
reg wr_en;
wire tx_fifo_full;
reg i_start;
wire o_dht11_data_ready;
wire o_busy;
wire [7:0] o_temp_data;
wire [7:0] o_hum_data;
wire o_dht11_error;
uart_tx_fifo #(
.CLK_FREQ(CLK_FREQ),
.BAUD_RATE(115200),
.FIFO_SIZE(8)
) uart_tx_inst (
.clk(clk),
.wr_en(wr_en),
.wr_data(wr_data),
.fifo_full(tx_fifo_full),
.tx_pin(tx)
);
dht11_interface dht11_inst (
.i_clk(clk),
.io_dht11_sig(io_dht11_sig),
.i_start(i_start),
.o_dht11_data_ready(o_dht11_data_ready),
.o_busy(o_busy),
.o_temp_data(o_temp_data),
.o_hum_data(o_hum_data),
.o_dht11_error(o_dht11_error)
);
// === FSM ===
localparam WAIT = 0, MESURE = 1, SEND_FIFO1 = 2, SEND_FIFO2 = 3;
reg [2:0] state = WAIT;
reg [31:0] delay_counter = 0;
reg strobe2s = 0;
// 2s counter
always_ff @(posedge clk) begin
if (delay_counter == CLK_FREQ * 2 - 1) begin
delay_counter <= 0;
strobe2s <= 1;
end else begin
delay_counter <= delay_counter + 1;
strobe2s <= 0;
end
end
always_ff @(posedge clk) begin
case (state)
WAIT: begin
i_start <= 0;
wr_en <= 0;
if (strobe2s) begin
state <= MESURE;
i_start <= 1;
end
end
MESURE: begin
i_start <= 0;
if (o_dht11_data_ready && !o_busy) begin
state <= SEND_FIFO1;
wr_data <= o_temp_data;
wr_en <= 1;
end
end
SEND_FIFO1: begin
wr_data <= o_hum_data;
wr_en <= 1;
state <= SEND_FIFO2;
end
SEND_FIFO2: begin
wr_en <= 0;
state <= WAIT;
end
default: state <= WAIT;
endcase
end
endmodule