论坛» 综合技术» 基础知识

关于FPGA串口不停发送的问题

助工
2016-06-05 19:00 1楼

大家好,今天我在做FPGA单工发送数据的时候,FPGA不停向主机发数据,并没有得到我的触发指令,请大家帮忙看看哪里出问题了,谢谢谢谢。

module serial_t(rst_n,clk_50MHz,clk_div,txd_data,txd_start,txd_busy,tx,show); input rst_n,clk_50MHz,clk_div,txd_start; input [7:0]txd_data; output txd_busy,tx,show; reg txd_busy=0,tx=1; reg [3:0]next_state=4'b0000,current_state=4'b0000; reg tx_flag_t1,tx_flag_t2; wire tx_flag_negedge; always @(posedge clk_50MHz or negedge rst_n)//用于检测txd_start的下降沿 begin if(!rst_n) begin tx_flag_t1<=0; tx_flag_t2<=0; end else begin tx_flag_t1<=txd_start; tx_flag_t2<=tx_flag_t1; end end assign show=next_state[2]; assign tx_flag_negedge = (~tx_flag_t2)&tx_flag_t1; always @(posedge clk_50MHz or negedge rst_n) begin if(~rst_n) begin txd_busy<=1'b0; end else if(tx_flag_negedge) begin txd_busy<=1; end else if(next_state==4'b0000) begin txd_busy<=0; end end always @(posedge clk_div or negedge rst_n) begin if(rst_n==0) begin current_state<=4'b0000; end else begin current_state<=next_state; end end always @(current_state or txd_start) begin case(current_state) 4'b0000: begin if(txd_start) begin next_state=4'b0100; end end 4'b0100: if(clk_div) next_state=4'b1000; //开始位 4'b1000: if(clk_div) next_state=4'b1001; //第1位 4'b1001: if(clk_div) next_state=4'b1010; //第2位 4'b1010: if(clk_div) next_state=4'b1011; //第3位 4'b1011: if(clk_div) next_state=4'b1100; //第4位 4'b1100: if(clk_div) next_state=4'b1101; //第5位 4'b1101: if(clk_div) next_state=4'b1110; //第6位 4'b1110: if(clk_div) next_state=4'b1111; //第7位 4'b1111: if(clk_div) next_state=4'b0101; //第8位 4'b0101: if(clk_div) next_state=4'b0000; else if(txd_start) next_state=4'b0100; default: next_state=4'b0000; endcase end always @(posedge clk_div or negedge rst_n) begin if(rst_n==0) begin tx<=1; end else begin case(next_state) 4'b0000: tx<=1; 4'b0100: tx<=0; 4'b1000: tx<=txd_data[0]; 4'b1001: tx<=txd_data[1]; 4'b1010: tx<=txd_data[2]; 4'b1011: tx<=txd_data[3]; 4'b1100: tx<=txd_data[4]; 4'b1101: tx<=txd_data[5]; 4'b1110: tx<=txd_data[6]; 4'b1111: tx<=txd_data[7]; 4'b0101: tx<=1; default: tx<=1; endcase end end endmodule

高工
2016-06-07 22:12 2楼

帮顶下吧

专家
2016-06-09 21:06 3楼
这个不懂。从程序设计的角度看应该加一个触发条件
共3条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]