新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2022-8-9
- 在线时间
- 7 小时
|
10金钱
使用k7系列fpga做cmos图像采集存储至bram中再由uart串口发送回上位机,这里uart每次会重复发送数据,请问是哪里有问题呢,代码如下:
- //*******************uart***********************
- wire rx_data_done;
- wire [7:0] rx_data;
- parameter CLK_FRE = 200; //Mhz
- localparam IDLE = 0;
- localparam SEND = 1; //send
- localparam WAIT = 2; //wait 1 second and send uart received data
- localparam STOP = 3;
- reg [7:0] tx_data;
- reg [7:0] tx_str;
- reg tx_data_valid;
- wire tx_data_ready;
- reg [7:0] tx_cnt;
- wire rx_data_valid;
- wire rx_data_ready;
- reg [3:0] state;
- reg [23:0] pixel_cnt;
- reg [23:0] off_cnt;
- wire uart_vaild;
- wire end_cnt;
- reg uart_cnt;
- reg [31:0] cnt_1s;
- reg flag_1s;
- assign rx_data_done = rx_data_valid;
- assign rx_data_ready = 1'b1; //always can receive data
- assign end_cnt = (off_cnt < 1000)? 1'b1:1'b0;
- assign uart_vaild = uart_en && uart_cnt && end_cnt && bram_read_en;
- always@(posedge sys_clk or negedge sys_rst_n)
- begin
- if(sys_rst_n == 1'b0)
- begin
- uart_cnt <= 1'b0;
- cnt_1s <= 32'd0;
- end
- else
- begin
- if(pixel_cnt < 2500)
- begin
- uart_cnt <= 1'b1;
- flag_1s <= 1'b0;
- end
- else
- begin
- uart_cnt <= 1'b0;
- cnt_1s <= cnt_1s + 32'd1;
- if(cnt_1s == 32'd200000000)
- begin
- cnt_1s <= 32'd0;
- flag_1s <= 1'b1;
- end
- end
- end
- end
- always@(posedge sys_clk or negedge sys_rst_n)
- begin
- if(sys_rst_n == 1'b0)
- begin
- tx_data <= 8'd0;
- state <= IDLE;
- tx_data_valid <= 1'b0;
- pixel_cnt <= 24'b0;
- off_cnt <= 24'b0;
- end
- else
- begin
- if(flag_1s == 1'b1)
- pixel_cnt <= 24'b0;
- if (uart_vaild == 1'b1)
- begin
- state <= IDLE;
- case(state)
- IDLE:
- state <= SEND;
- SEND:
- begin
- tx_data <= data_read;
- if(tx_data_valid && tx_data_ready) //last byte sent is complete
- begin
- tx_data_valid <= 1'b0;
- state <= WAIT;
- end
- else if(~tx_data_valid)
- begin
- tx_data_valid <= 1'b1;
- end
- end
- WAIT:
- begin
- state <= STOP;
- end
- STOP:
- begin
- pixel_cnt <= pixel_cnt + 24'd1;
- addr_read <= addr_read + 24'd1;
- off_cnt <= off_cnt + 24'd1;
- if(addr_read == 24'd1036801)
- // if(addr_read == 24'd629856)
- begin
- addr_read <= 24'd0;
- end
- end
- default:
- state <= IDLE;
- endcase
- end
- end
- end
- uart_rx#
- (
- .CLK_FRE(CLK_FRE),
- .BAUD_RATE(115200)
- ) uart_rx_inst
- (
- .clk (sys_clk ),
- .rst_n (sys_rst_n ),
- .rx_data (rx_data ),
- .rx_data_valid (rx_data_valid ),
- .rx_data_ready (rx_data_ready ),
- .rx_pin (uart_rx )
- );
- uart_tx#
- (
- .CLK_FRE(CLK_FRE),
- .BAUD_RATE(115200)
- ) uart_tx_inst
- (
- .clk (sys_clk ),
- .rst_n (sys_rst_n ),
- .tx_data (tx_data ),
- .tx_data_valid (tx_data_valid ),
- .tx_data_ready (tx_data_ready ),
- .tx_pin (uart_tx )
- );
- //*******************uart***************************
复制代码 uart发送数据的代码
assign end_cnt = (off_cnt < 1000)? 1'b1:1'b0;
这里设定发送1000个数据,实际收到2000个,每个数据重复发送一次,请问如何解决,谢谢!
|
-
串口收到的数据
|