基于FPGA的UART协议实现(通过线性序列机)


回环测试综合资源使用情况以及糟糕条件下的Fmax:


通过串口助手测试: 发送ab回传ab显示。

///////uart 发送模块;
module uart_tx (
input wire i_clk , //100MHZ;
input wire i_rst_n ,
input wire i_send_en , //打开发送;
input wire [:] i_data_i ,
output wire o_tx ,
output wire o_tx_done //发送完成指示;
);
/////////////////波特率选择;
parameter [:] BPS_CNT_MAX = 100_000_000/; //时钟根据需要修改;
//parameter [14:0] BPS_CNT_MAX = 15'd2; //仿真使用2;缩短仿真时间;
reg [:] r_i_send_en; //同步两拍;
always @(posedge i_clk) begin
r_i_send_en <= {r_i_send_en[],i_send_en};
end
reg [:] tx_data;
always @(posedge i_clk or negedge i_rst_n) begin
if (~i_rst_n) begin
tx_data <= ;
end //if
else begin
if (r_i_send_en[]) begin
tx_data <= i_data_i;
end
else begin
tx_data <= tx_data;
end
end //else
end //always
reg tx_en; //整个发送区间计数使能;
reg [:] bps_cnt;
reg [:] cnt;
always @(posedge i_clk or negedge i_rst_n) begin
if (~i_rst_n) begin
tx_en <= ;
end //if
else begin
if (r_i_send_en[]) begin
tx_en <= 'b1;
end
else begin
if ((cnt == 'd10) && (bps_cnt == (BPS_CNT_MAX - 15'd1))) begin
tx_en <= 'b0;
end
end
end //else
end //always
always @(posedge i_clk or negedge i_rst_n) begin
if (~i_rst_n) begin
bps_cnt <= ;
end //if
else begin
if (tx_en) begin
if (bps_cnt == (BPS_CNT_MAX - 'd1)) begin
bps_cnt <= ;
end
else begin
bps_cnt <= bps_cnt + 'd1;
end
end
else begin
bps_cnt <= ;
end
end //else
end //always
always @(posedge i_clk or negedge i_rst_n) begin
if (~i_rst_n) begin
cnt <= ;
end //if
else begin
if (tx_en) begin
if (bps_cnt == (BPS_CNT_MAX - 'd1)) begin
cnt <= cnt + 'd1; //bps计数到最大值则cnt加1;
end
end
else begin
cnt <= ;
end
end //else
end //always
reg tx_done;
reg tx;
always @(posedge i_clk) begin
case (cnt)
: begin tx <= 'b1;tx_done <= 1'b0; end //tx默认为高电平;
: begin tx <= 'b0; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= tx_data[]; end
: begin tx <= 'b1;tx_done <= 1'b1;end //拉高tx,产生发送完成指示信号;
default: begin tx <= 'b1;tx_done <= 1'b0; end
endcase //case
end //always
assign o_tx = tx;
assign o_tx_done = tx_done; endmodule
////////uart 接收模块;
module uart_rx (
input wire i_clk , //100M;
input wire i_rst_n ,
input wire i_rx ,
output wire o_rx_finish ,
output wire [:] o_rx_data
);
/////////////////波特率选择;默认115200bps/s;
parameter [:] p_bps_max = 100_000_000//;
reg [:] r_rx;
always @(posedge i_clk) begin
r_rx <= {r_rx[],i_rx};
end
reg [:] r_bps_cnt;
reg [:] r_position_cnt;
reg r_cnt_en;
always @(posedge i_clk,negedge i_rst_n) begin
if (~i_rst_n) begin
r_cnt_en <= ;
end //if
else begin
if (r_rx == 'b10) begin
r_cnt_en <= 'b1;
end
else begin
if (((r_position_cnt == 'd7) && (r_rx[1])) || (r_position_cnt == 8'd159)) begin
r_cnt_en <= 'b0;
end
end
end //else
end //always
always @(posedge i_clk,negedge i_rst_n) begin
if (~i_rst_n) begin
r_bps_cnt <= ;
end //if
else begin
if (r_cnt_en) begin
if (r_bps_cnt == (p_bps_max -'d1)) begin
r_bps_cnt <= ;
end
else begin
r_bps_cnt <= r_bps_cnt + 'd1;
end
end
else begin
r_bps_cnt <= ;
end
end //else
end //always
////////////位置计数逻辑;
always @(posedge i_clk,negedge i_rst_n) begin
if (~i_rst_n) begin
r_position_cnt <= ;
end //if
else begin
if (r_cnt_en) begin
if (r_bps_cnt == (p_bps_max-'d1)) begin
r_position_cnt <= r_position_cnt + 'd1;
end
end
else begin
r_position_cnt <= ;
end
end //else
end //always
reg [:] r_rx_data;
always @(posedge i_clk,negedge i_rst_n) begin
if (~i_rst_n) begin
r_rx_data <= ;
end //if
else begin
case (r_position_cnt)
'd23: begin r_rx_data[0] <= r_rx[1]; end
'd39: begin r_rx_data[1] <= r_rx[1]; end
'd55: begin r_rx_data[2] <= r_rx[1]; end
'd71: begin r_rx_data[3] <= r_rx[1]; end
'd87: begin r_rx_data[4] <= r_rx[1]; end
'd103: begin r_rx_data[5] <= r_rx[1]; end
'd119: begin r_rx_data[6] <= r_rx[1]; end
'd135: begin r_rx_data[7] <= r_rx[1]; end
default: ;
endcase
end //else
end //always assign o_rx_finish = (r_position_cnt >= 'd139) ? 1'b1 : 'b0;
assign o_rx_data = r_rx_data; endmodule // end the uart_rx model;
top.v就不贴了,勿做商业用途。
旧版工程完整源代码可在码云中查看和下载:https://gitee.com/kingstacker/uart
以上。
基于FPGA的UART协议实现(通过线性序列机)的更多相关文章
- 小梅哥FPGA数字逻辑设计教程——基于线性序列机的TLC5620型DAC驱动设计
基于线性序列机的TLC5620型DAC驱动设计 目录 TLC5620型DAC芯片概述: 2 TLC5620型DAC芯片引脚说明: 2 TLC5620型DAC芯片详细介绍: 3 TLC ...
- 可控线性序列机(查看除了inout端口外的其他变量的波形的方法)
可控线性序列机: 可控:有个控制端控制何时输出线性序列. 线性序列机:输出一个线性序列. 知识点: 1.包含多个判定条件时用英文()括起来,用&&连接. 2.使能端EN的设置(类似于D ...
- 基于FPGA的Uart接收图像数据至VGA显示
系统框图 前面我们设计了基于FPGA的静态图片显示,接下来我们来做做基于FPGA的动态图片显示,本实验内容为:由PC端上位机软件通过串口发送一幅图像数据至FPGA,FPGA内部将图像数据存储,最后扫描 ...
- 基于FPGA的XPT2046触摸控制器设计
基于FPGA的XPT2046触摸控制器设计 小梅哥编写,未经许可,文章内容和所涉及代码不得用于其他商业销售的板卡 本实例所涉及代码均可通过向 xiaomeige_fpga@foxmail.com 发 ...
- 基于FPGA的中值滤波算法实现
在这一篇开篇之前,我需要解决一个问题,上一篇我们实现了基于FPGA的均值滤波算法的实现,最后的显示效果图上发现有一些黑白色的斑点,我以为是椒盐噪声,然后在做基于FPGA的中值滤波算法的实验时,我发现黑 ...
- 基于FPGA的Sobel边缘检测的实现
前面我们实现了使用PC端上位机串口发送图像数据到VGA显示,通过MATLAB处理的图像数据直接是灰度图像,后面我们在此基础上修改,从而实现,基于FPGA的动态图片的Sobel边缘检测.中值滤波.Can ...
- 基于FPGA的腐蚀膨胀算法实现
本篇文章我要写的是基于的腐蚀膨胀算法实现,腐蚀膨胀是形态学图像处理的基础,,腐蚀在二值图像的基础上做"收缩"或"细化"操作,膨胀在二值图像的基础上做" ...
- 基于FPGA的肤色识别算法实现
大家好,给大家介绍一下,这是基于FPGA的肤色识别算法实现. 我们今天这篇文章有两个内容一是实现基于FPGA的彩色图片转灰度实现,然后在这个基础上实现基于FPGA的肤色检测算法实现. 将彩色图像转化为 ...
- 【转】基于FPGA的Sobel边缘检测的实现
前面我们实现了使用PC端上位机串口发送图像数据到VGA显示,通过MATLAB处理的图像数据直接是灰度图像,后面我们在此基础上修改,从而实现,基于FPGA的动态图片的Sobel边缘检测.中值滤波.Can ...
随机推荐
- 自定义分页及Cookie、Session机制
分页 自定义分页 data = [] , ): tmp = {"id": i, "name": "alex-{}".format(i)} d ...
- XML 与 JSON大PK
导读 XML 和 JSON 是现今互联网中最常用的两种数据交换格式.XML 格式由 W3C 于 1996 年提出.JSON 格式由 Douglas Crockford 于 2002 年提出.虽然这两种 ...
- Winform MDI窗体切换不闪烁的解决办法(测试通过)
https://stackoverflow.com/questions/5817632/beginupdate-endupdate-for-datagridview-request SuspendLa ...
- Django之admin中管理models中的表格
Django之admin中管理models中的表格 django中使用admin管理models中的表格时,如何将表格注册到admin中呢? 具体操作就是在项目文件夹中的app文件夹中的admin中注 ...
- 【转】Restful是什么
REST的概念是什么 维基百科 表现层状态转换(REST,英文:Representational State Transfer)是Roy Thomas Fielding博士于2000年在他的博士论文 ...
- text-decoration、text-decoration-color、text-decoration-line、text-decoration-style属性
text-decoration:over-line 定义上划线 text-decoration:line-through 定义删除线 text-decoration:underline 定义下划 ...
- 【学亮IT手记】angularJS+select2多选下拉框实例
永远保持对大部分知识的好奇心,学习从不枯燥,也没有被逼学习一说,乐此不疲才是该有的心态和境界!!! 引入相关js库: html部分代码: angularJS定义数据源变量:
- php redis常用方法代码例子
1,connect 描述:实例连接到一个Redis.参数:host: string,port: int返回值:BOOL 成功返回:TRUE;失败返回:FALSE 示例: <?php $redis ...
- LeetCode & Online Programming Learning Platform
leetcode LeetCode is the best platform to help you enhance your skills, expand your knowledge and pr ...
- Http请求笔记
1 HTTP请求报文组成: 请求行:请求方法 url 协议版本 请求头:报文头-属性名:属性值 Accept属性告诉服务端-客户端接受什么类型的响应,可为一个或多个mime类型值 Cookie:服务端 ...