module Serial_Data_TX(clk, clk_125KHZ, DataIn, TX_star, DataOut, TX_done);
input clk; //系统时钟40MHz
input clk_125KHZ; //同步时钟125KHZ
input [63:0] DataIn; //需要发送的数据
input TX_star; //发送启动信号
output DataOut; //串口发送
output TX_done; //发送结束标志
//端口变量声明
wire clk;
wire clk_125KHZ;
wire [63:0] DataIn;
wire TX_star;
reg DataOut;
reg TX_done;
//发送数据寄存器
reg [64:0] Data;
always @(posedge clk) Data <= {DataIn , 1'b0}; //64位数据位+1位起始位0
//发送状态机
reg state = 0; //状态机
parameter IDLE = 1'b0; //空闲
parameter SEND = 1'b1; //发送
reg [6:0] i; //发送数据计数器
always @ (posedge clk)begin
case(state)
IDLE:begin //空闲状态
i <= 7'd0;
DataOut <= 1'b1;
TX_done <= 1'b0;
if(TX_star) state <= SEND;
end
SEND:begin //发送状态,从低位开始发送
if(clk_125KHZ)
if( i < 7'd65 )begin
DataOut <= Data[i];
i <= i + 1'b1;
end
else begin
TX_done <= 1'b1; //发送完成
i <= 7'd0;
DataOut <= 1'b1;
state <= IDLE;
end
end
endcase
end
endmodule
以上是代码,起始位0+64位数据+结束位1 串行传输。
仿真没有问题,我发现烧写到板子上,即使没有输入信号,也会有个840us周期的方波。已经排除了管脚复用。
可能是软件问题,但是用ISIM仿真为什么没有问题呢?
|