【问题标题】:Why can't I simulate my receiver code for UART?为什么我不能模拟 UART 的接收器代码?
【发布时间】:2021-05-01 15:40:06
【问题描述】:

我正在尝试使用 Verilog 在测试台中模拟 uart 接收器。我强制所有输入位,时钟和复位,我强制RsRx,接收器的串行输入,以获得输出rx_data,但rx_data总是

波特发生器运行良好,但接收器却不行。我认为问题出在测试台上,因为接收器的代码是由 ARM 提供的。 谁能帮帮我?

module TEST_Uart() ;
reg HCLK=0 ;
reg HRESETn=0 ;
wire b_tick ;
wire rx_done ;
reg RsRx=1 ;
wire [7:0]rx_data ;
       initial 
        forever #1 HCLK = ~HCLK;
initial
begin
@(posedge HCLK);
HRESETn=1 ;
end
BAUDGEN uBAUDGEN(
    .clk(HCLK),
    .resetn(HRESETn),
    .baudtick(b_tick)
  );
  
  
 //UART receiver
      UART_RX uUART_RX(
        .clk(HCLK),
        .resetn(HRESETn),
        .b_tick(b_tick),
        .rx(RsRx),
        .rx_done(rx_done),
        .dout(rx_data[7:0])
      );
     
      task UART_WRITE_BYTE;
          input [7:0] i_Data;
          integer     ii;
          begin
             
            // Send Start Bit
           RsRx <= 1'b0;
           
             
             
            // Send Data Byte
            for (ii=0; ii<8; ii=ii+1)
              begin
                RsRx <= i_Data[ii];
     
              end
             
            // Send Stop Bit
            RsRx <= 1'b1;
           
           end
        endtask // UART_WRITE_BYTE
      
      
     initial
         begin
                      
           // Send a command to the UART (exercise Rx)
           @(posedge HCLK);
           UART_WRITE_BYTE(8'h3F);
           @(posedge HCLK);
                  
           // Check that the correct command was received
           if (rx_data == 8'h3F)
             $display("Test Passed - Correct Byte Received");
           else
             $display("Test Failed - Incorrect Byte Received");
         end
endendmodule

【问题讨论】:

    标签: verilog uart


    【解决方案1】:

    您需要在UART_WRITE_BYTE task 中添加延迟。目前,当您运行仿真并查看波形时,RsRx 似乎始终为 1。这是因为您的所有作业都发生在同一模拟时间。

    您需要在每次分配之间添加延迟。例如,在下面的代码中,我在每次赋值后添加了 5 的延迟:

    task UART_WRITE_BYTE;
        input [7:0] i_Data;
        integer     ii;
        begin
            // Send Start Bit
            RsRx <= 1'b0;
            #5;
    
            // Send Data Byte
            for (ii=0; ii<8; ii=ii+1)
            begin
                RsRx <= i_Data[ii];
                #5;
            end
    
            // Send Stop Bit
            RsRx <= 1'b1;
            #5;
        end
    endtask // UART_WRITE_BYTE
    

    我使用 5 只是为了演示原理。延迟实际上应该与波特率有关。您可能想用与b_tick 信号边缘相关的代码替换固定延迟,例如:

    @(posedge b_tick);
    

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 1970-01-01
      • 2015-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多