当前位置:首页 > 电源 > 数字电源
[导读]========================================================================== //----------------------------------------------------- // Design Name : uart // File Name : uart.v // Function : S

==========================================================================
//-----------------------------------------------------
// Design Name : uart
// File Name   : uart.v
// Function    : Simple UART
// Coder       : Deepak Kumar Tala
//-----------------------------------------------------
module uart (
reset          ,
txclk          ,
ld_tx_data     ,
tx_data        ,
tx_enable      ,
tx_out         ,
tx_empty       ,
rxclk          ,
uld_rx_data    ,
rx_data        ,
rx_enable      ,
rx_in          ,
rx_empty
);
// Port declarations
input        reset          ;
input        txclk          ;
input        ld_tx_data     ;
input [7:0] tx_data        ;
input        tx_enable      ;
output       tx_out         ;
output       tx_empty       ;
input        rxclk          ;
input        uld_rx_data    ;
output [7:0] rx_data        ;
input        rx_enable      ;
input        rx_in          ;
output       rx_empty       ;

// Internal Variables
reg [7:0]    tx_reg         ;
reg          tx_empty       ;
reg          tx_over_run    ;
reg [3:0]    tx_cnt         ;
reg          tx_out         ;
reg [7:0]    rx_reg         ;
reg [7:0]    rx_data        ;
reg [3:0]    rx_sample_cnt ;
reg [3:0]    rx_cnt         ;
reg          rx_frame_err   ;
reg          rx_over_run    ;
reg          rx_empty       ;
reg          rx_d1          ;
reg          rx_d2          ;
reg          rx_busy        ;

// UART RX Logic
always @ (posedge rxclk or posedge reset)
if (reset) begin
rx_reg        <= 0;
rx_data       <= 0;
rx_sample_cnt <= 0;
rx_cnt        <= 0;
rx_frame_err <= 0;
rx_over_run   <= 0;
rx_empty      <= 1;
rx_d1         <= 1;
rx_d2         <= 1;
rx_busy       <= 0;
end else begin
// Synchronize the asynch signal
rx_d1 <= rx_in;
rx_d2 <= rx_d1;
// Uload the rx data
if (uld_rx_data) begin
    rx_data <= rx_reg;
    rx_empty <= 1;
end
// Receive data only when rx is enabled
if (rx_enable) begin
    // Check if just received start of frame[!--empirenews.page--]
    if (!rx_busy && !rx_d2) begin
      rx_busy       <= 1;
      rx_sample_cnt <= 1;
      rx_cnt        <= 0;
    end
    // Start of frame detected, Proceed with rest of data
    if (rx_busy) begin
       rx_sample_cnt <= rx_sample_cnt + 1;
       // Logic to sample at middle of data
       if (rx_sample_cnt == 7) begin
          if ((rx_d2 == 1) && (rx_cnt == 0)) begin
            rx_busy <= 0;
          end else begin
            rx_cnt <= rx_cnt + 1;
            // Start storing the rx data
            if (rx_cnt > 0 && rx_cnt < 9) begin
              rx_reg[rx_cnt - 1] <= rx_d2;
            end
            if (rx_cnt == 9) begin
               rx_busy <= 0;
               // Check if End of frame received correctly
               if (rx_d2 == 0) begin
                 rx_frame_err <= 1;
               end else begin
                 rx_empty     <= 0;
                 rx_frame_err <= 0;
                 // Check if last rx data was not unloaded,
                 rx_over_run <= (rx_empty) ? 0 : 1;
               end
            end
          end
       end
    end
end
if (!rx_enable) begin
    rx_busy <= 0;
end
end

// UART TX Logic
always @ (posedge txclk or posedge reset)
if (reset) begin
tx_reg        <= 0;
tx_empty      <= 1;
tx_over_run   <= 0;
tx_out        <= 1;
tx_cnt        <= 0;
end else begin
   if (ld_tx_data) begin
      if (!tx_empty) begin
        tx_over_run <= 0;
      end else begin
        tx_reg   <= tx_data;
        tx_empty <= 0;
      end
   end
   if (tx_enable && !tx_empty) begin
     tx_cnt <= tx_cnt + 1;
     if (tx_cnt == 0) begin
       tx_out <= 0;
     end
     if (tx_cnt > 0 && tx_cnt < 9) begin
        tx_out <= tx_reg[tx_cnt -1];
     end
     if (tx_cnt == 9) begin
       tx_out <= 1;
       tx_cnt <= 0;
       tx_empty <= 1;
     end
   end
   if (!tx_enable) begin
     tx_cnt <= 0;
   end
end

endmodule

本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

舍弗勒以"专注驱动技术的科技公司"为主题亮相IAA MOBILITY 2025(B3馆B40展台) 合并纬湃科技后首次亮相IAA MOBILITY,展示拓展后的汽车产品组合 凭借在软件、...

关键字: 电气 软件 驱动技术 BSP

香港2025年 9月12日 /美通社/ -- 全球领先的互联网社区创建者 - 网龙网络控股有限公司 ("网龙"或"本公司",香港交易所股票代码:777)欣然宣布,其子公司My...

关键字: AI 远程控制 控制技术 BSP

深圳2025年9月11日 /美通社/ -- 2025 年 9 月 10 日,第 26 届中国国际光电博览会(简称 "CIOE 中国光博会")在深圳盛大开幕。本届展会吸引力再创新高,全球超3800家优质...

关键字: 自动化 光电 CIO BSP

天津2025年9月11日 /美通社/ -- 国际能源署(IEA)数据显示,2024 年全球数据中心电力消耗达 415 太瓦时,占全球总用电量的 1.5%,预计到 2030 年,这一数字将飙升至 945 太瓦时,近乎翻番,...

关键字: 模型 AI 数据中心 BSP

北京2025年9月11日 /美通社/ -- 国际9月11日上午,2025年中国国际服务贸易交易会(以下简称"服贸会")—体育赛事经济高质量发展大会现场,北京经济技术开发区工委委员、管委会副主...

关键字: 5G BSP GROUP MOTOR

柏林2025年9月9日 /美通社/ -- 2025年9月5日,纳斯达克上市公司优克联集团(NASDAQ: UCL)旗下全球互联品牌GlocalMe,正式亮相柏林国际消费电子展(IFA 2025),重磅推出融合企...

关键字: LOCAL LM BSP 移动网络

深圳2025年9月9日 /美通社/ -- PART 01活动背景 当技术的锋芒刺穿行业壁垒,万物互联的生态正重塑产业疆域。2025年,物联网产业迈入 "破界创造"与"共生进化" 的裂变时代——AI大模型消融感知边界,...

关键字: BSP 模型 微信 AIOT

"出海无界 商机无限"助力企业构建全球竞争力 深圳2025年9月9日 /美通社/ -- 2025年8月28日, 由领先商业管理媒体世界经理人携手环球资源联合主办、深圳•前海出海e站通协办的...

关键字: 解码 供应链 AI BSP

柏林2025年9月9日 /美通社/ -- 柏林当地时间9月6日,在2025德国柏林国际电子消费品展览会(International Funkausstellung...

关键字: 扫地机器人 耳机 PEN BSP

武汉2025年9月9日 /美通社/ -- 7月24日,2025慧聪跨业品牌巡展——湖北•武汉站在武汉中南花园酒店隆重举办!本次巡展由慧聪安防网、慧聪物联网、慧聪音响灯光网、慧聪LED屏网、慧聪教育网联合主办,吸引了安防、...

关键字: AI 希捷 BSP 平板
关闭