我正在尝试制作一个UART,但是如果数据是从另一个模块传输的,那么数据会传输到z位置

问题描述 投票:0回答:1

我正在尝试制作一个UART发射器。如果直接在模块中初始化数据就可以工作;一切输出都很好。但是,如果您从另一个模块传输数据,则所有输出数据都会传输到

z
(高阻抗)位置。

我从中获取数据的第一个模块,为了尝试修复它,我尽可能地简化了它:

module Ever_date (
    input wire clk,          
    output wire out_date
);

    reg [7:0] date;

    always @(posedge clk) begin
    date <= 8'b0111_1101;
    end
endmodule

第二个数据传输模块:

module UART_Transmitter (
input wire clk, // Clock signal
input wire [7:0] data, // Data to transfer
output reg tx // UART output signal
);
reg wirst = 1'b0;
reg data_ready = 1'b1;
reg reset = 1'b0;

reg [3:0] bit_counter = 4'd0; // Bit counter
reg [10:0] shift_reg = 11'b0; // Shift register for data

always @(posedge clk) begin
    if (reset) begin
        bit_counter <= 4'd0; // Reset the bit counter
        shift_reg <= 11'b0; // Reset the shift register
        tx <= 1'b1; // Setting the logical unit on the transmission line
    end else if (data_ready) begin
        case (bit_counter)
            4'd0: begin // Start bit
            shift_reg <= {1'b1, data}; // Generating the start bit and data
            tx <= 1'b0; // Setting a logical zero on the transmission line
            bit_counter <= bit_counter + 1; // Bit counter increment
            end
            4'd16: begin // The stop bit //16 stands because only the positive clock frequency is considered
                bit_counter <= 4'd0; // Resetting the bit counter for the next byte
            end
            default: begin // Data
                shift_reg <= {shift_reg[9:0], 1'b0}; // Data shift for transmission
                tx <= shift_reg[10]; // Sending data bits
                bit_counter <= bit_counter + 1; // Bit counter increment
            end
        endcase
    end else begin
        tx <= 1'b1; // Setting the logical unit on the transmission line if the data is not ready
    end
end

endmodule

主要模块:

module main
(
    input wire clkin,  
    output wire DI
);

    Ever_date Ever_date(
        .clk(clk),
        .out_date(in_tx)
    );

   UART_Transmitter uart_transmitter (  //out
         .clk(clk),
         .data(in_tx),      //in
         .tx(out_tx)        //out
    );

  assign DE = out_tx;

endmodule

我没有测试台。使用 ISE 设计套件内置的仿真来创建此波形:

enter image description here

将传输数据的模块简化到最少。

verilog uart
1个回答
0
投票

当您编译代码时,您的工具应该向您发出警告。

例如,当我在 EDA Playground 上编译你的代码时,我收到以下警告:

            4'd16: begin // The stop bit //16 stands because only the positive clock frequency is considered
                |
xmvlog: *W,INTOVF (testbench.sv,37|16): bit overflow during conversion from text [2.5(IEEE)] (4 bits).
    Top level design units:
        main
xmelab: *W,DSEMEL: This SystemVerilog design will be simulated as per IEEE 1800-2009 SystemVerilog simulation semantics. Use -disable_sem2009 option for turning off SV 2009 simulation semantics.
         .data(in_tx),      //in
                   |
xmelab: *W,CUVMPW (./testbench.sv,66|19): port sizes differ in port connection(1/8) for the instance(main) .
        .out_date(in_tx)
                      |
xmelab: *W,CSINFI (./testbench.sv,61|22): implicit wire has no fanin (main.in_tx).
        .clk(clk),
               |
xmelab: *W,CSINFI (./testbench.sv,60|15): implicit wire has no fanin (main.clk).

您需要修复代码中的所有这些警告,因为它们直接识别代码中的错误。

您应该阅读您的工具的文档,看看它是否能够生成警告,如果可以,如何查看警告。如果该工具不具备此功能,您需要切换到 Verilog 模拟器,例如 Playground 上提供的模拟器之一。

我还建议创建您自己的简单测试平台:TB 101

© www.soinside.com 2019 - 2024. All rights reserved.