|
功能是 串口接收一帧数据,保存下来,然后判断, 发现发送第一帧数据的时候程序正常执行, 第二帧数据就不对了,然后第三次OK ,第四4 NG,看了半天找不到问题
always@(posedge clk or negedge rst_n)
if(!rst_n)
begin
sync_state <= IDEL;
end
else
if(neg_rx_int==1) begin
case(sync_state)
IDEL:
if(rx_data == 8'hee) //开始字符
begin
sync_state <= S2;
rxcounter <= 8'h00;
end
else ;
S2:
if(rx_data == 8'hff) begin //结束字符
sync_state <= S3;
rxcounter <= 8'h00;
end
else if(rx_data ==8'hee) begin //开始字符
rxcounter <= 8'h00;
sync_state<=S2;
end
else begin
rx_store[rxcounter] <= rx_data; //串口接收的数据保存
rxcounter <= rxcounter +1'b1;
end
S3: begin sync_state <= IDEL;
end
default: ;
endcase
end
else ; |
|