中级会员
- 积分
- 314
- 金钱
- 314
- 注册时间
- 2015-1-25
- 在线时间
- 83 小时
|
30金钱
利用串口发送数据,计划发送40个字节,
如果 判断 发送计数器cnt_uart_tx
cnt_uart_tx == 6'd39 最后一个字节不对,字节个数没问题,但是最后一个赋值有问题,应该为0x1b
1A AB AC 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 36
如果 判断 cnt_uart_tx == 6'd40 发送41个字节,最后为
1A AB AC 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 1b 1b
求指教!
reg tx_cnt_en; //发送数据使能计数器
//读取uart_fifo_tx 内容
always @(posedge clk or negedge rst_n)
if(!rst_n)
tx_cnt_en <= 1'b0;
// else if(single_tx_posedge)
else if(r_tx_en)
tx_cnt_en <= 1'b1;
else if (cnt_uart_tx == 6'd39)
tx_cnt_en <= 1'b0;
else
tx_cnt_en <= tx_cnt_en;
assign tx_en = tx_cnt_en; // tx_en 为uart_en 使能信号
//读取计数器
reg [5:0]cnt_uart_tx;//发送计数器
always @(posedge clk or negedge rst_n)
if(!rst_n)
cnt_uart_tx <= 6'd0;
else if(tx_cnt_en && tx_done)begin
if(cnt_uart_tx == 6'd39)
cnt_uart_tx <= 6'd0;
else
cnt_uart_tx <= cnt_uart_tx + 1'b1;
end
else
cnt_uart_tx <= cnt_uart_tx;
always @(posedge clk or negedge rst_n)
if(!rst_n)
data_send <= 8'h00;
else if(tx_cnt_en) begin
case(cnt_uart_tx)
0:begin data_send <= 8'h1a; end
1:begin data_send <= 8'hab; end
2:begin data_send <= 8'hac; end
3:begin data_send <= 8'h01; end
4:begin data_send <= 8'h02; end
5:begin data_send <= 8'h03; end
6:begin data_send <= 8'h04; end
7:begin data_send <= 8'h05; end
8:begin data_send <= 8'h06; end
9:begin data_send <= 8'h07; end
10:begin data_send <= 8'h08;end
11:begin data_send <= 8'h09;end
12:begin data_send <= 8'h10;end
13:begin data_send <= 8'h11;end
14:begin data_send <= 8'h12;end
15:begin data_send <= 8'h13;end
16:begin data_send <= 8'h14;end
17:begin data_send <= 8'h15;end
18:begin data_send <= 8'h16;end
19:begin data_send <= 8'h17;end
20:begin data_send <= 8'h18;end
21:begin data_send <= 8'h19;end
22:begin data_send <= 8'h20;end
23:begin data_send <= 8'h21;end
24:begin data_send <= 8'h22;end
25:begin data_send <= 8'h23;end
26:begin data_send <= 8'h24;end
27:begin data_send <= 8'h25;end
28:begin data_send <= 8'h26;end
29:begin data_send <= 8'h27;end
30:begin data_send <= 8'h28;end
31:begin data_send <= 8'h29;end
32:begin data_send <= 8'h30;end
33:begin data_send <= 8'h31;end
34:begin data_send <= 8'h32;end
35:begin data_send <= 8'h33;end
36:begin data_send <= 8'h34;end
37:begin data_send <= 8'h35;end
38:begin data_send <= 8'h36;end
39:begin data_send <= 8'h1b;end
default: begin data_send <= 8'h00; end
endcase
|
|