Uart 接收
module uart_rx(clk,rst,s_data,data); //分頻接收資料.波特率9600bps
input clk,rst;
input s_data;
output [9:0] data;
reg en;
reg [1:0] t_data0,t_data1,t_data2,t_data3,t_data4,
t_data5,t_data6,t_data7,t_data8,t_data9;
reg [9:0] data;
reg [8:0] cnt;
reg [7:0] cnt1;
wire nedge;
reg Q;
reg Q1;
// ==================================================
//FSM
//===================================================
parameter idle = 1'b0,
trans = 1'b1;
reg [1:0] present_state, next_state;
always@(posedge clk or negedge rst)
begin
if(!rst) present_state <= idle;
else present_state <= next_state;
end
always@(*)
begin
case(present_state)
idle : if(nedge)
next_state = trans;
else
next_state = idle;
trans: if(cnt == 9'd324 && cnt1 == 8'd159)
next_state = idle;
else
next_state = trans;
endcase
end
always@(posedge clk or negedge rst)
begin
if(!rst)
en <= 1'b0;
else
begin
case(present_state)
idle : en <= 1'b0;
trans: en <= 1'b1;
endcase
end
end
//================================================
always@(posedge clk or negedge rst)
begin
if(!rst)
Q <= 1'b0;
else
Q <= s_data;
end
always@(posedge clk or negedge rst)
begin
if(!rst)
Q1 <= 1'b0;
else
Q1 <= Q;
end
//================================================
// 邊緣檢測
//================================================
assign nedge = Q1 & (~Q);
//================================================
// 分頻計數器
//================================================
always@(posedge clk or negedge rst)
begin
if(!rst) cnt <= 9'd0;
else if(en)
begin
if(cnt == 9'd324) cnt <= 9'd0;
else cnt <= cnt + 9'd1;
end
else cnt <= cnt;
end
always@(posedge clk or negedge rst)
begin
if(!rst) cnt1 <= 8'd0;
else if(cnt == 9'd324)
begin
if(cnt1 == 8'd159) cnt1 <= 8'd0;
else cnt1 <= cnt1 + 8'd1;
end
else cnt1 <= cnt1;
end
//============================================
always@(posedge clk)
begin
case(cnt1)
8'd8 : data[0] <= Q1;
8'd24 : data[1] <= Q1;
8'd40 : data[2] <= Q1;
8'd56 : data[3] <= Q1;
8'd72 : data[4] <= Q1;
8'd88 : data[5] <= Q1;
8'd104: data[6] <= Q1;
8'd120: data[7] <= Q1;
8'd136: data[8] <= Q1;
8'd152: data[9] <= Q1;
default:;
endcase
end
//===========================================
endmodule
待傳送資料din=1010101010,傳送資料dout依次為0101010101
相關文章
- MM32F0020 UART1中斷接收
- MM32F0020 UART1中斷接收和UART1中斷髮送
- MM32F0140 UART1中斷接收和UART1中斷髮送
- MM32F0140 UART1空閒中斷接收
- MM32F0020 UART1空閒中斷接收
- MM32F0140 UART1 DMA Interrupt RX and TX (UART1 DMA中斷接收和DMA中斷髮送資料)
- UART
- arm uart
- 串列埠UART串列埠
- UART學習
- UART協議協議
- (10)uart串列埠通訊串列埠
- 串列埠,COM口,UART,USART串列埠
- 串列埠收發UART(Verilog HDL)串列埠
- UART串列埠及Linux實現串列埠Linux
- Uart進行的串列埠收發串列埠
- 廣播接收器——接收系統廣播
- github上搜了下有ROS uart方面的GithubROS
- FPGA學習筆記03——UART串列埠FPGA筆記串列埠
- UART,I2C,SPI 介面總結
- MSM8953 Android 9.0 開啟uart串列埠Android串列埠
- 2(1)UART協議講解、架構設計協議架構
- Tasker配合ntfy接收通知
- golang 方法接收者Golang
- MQTT接收HEX(2/2)MQQT
- ACL 2020接收論文列表公開,接收率25.2%,你上榜了嗎?
- ESP32 wifi 串列埠轉發資料 UART micropythonWiFi串列埠Python
- 萬變不離其宗之UART要點總結
- 淺析 UART、RS232、TTL 之間的關係
- Qml接收QList<QVariantMap> 資料
- EBS-PO-接收入庫
- Go 接收命令列引數Go命令列
- MQTT接收字串(1/2)MQQT字串
- flutter: 深入通訊-接收端Flutter
- jQuery接收url的引數jQuery
- Python Basic - 遠端執行命令優化示例(迴圈接收直至接收完成)Python優化
- 定位模組LuatOS快速入門:源UART串列埠通訊串列埠
- 基於Linux的tty架構及UART驅動詳解Linux架構