天天看點

實作FPGA與ESP8266的連接配接與調試

1、在調試之前先要通過序列槽調試助手與網絡調試助手對ESP8266進行配置,但是根據AT指令集對其進行配置調試的時候,發現序列槽調試助手傳輸不了配置的指令集。對此,選擇對ESP8266先進行固件燒入。

實作FPGA與ESP8266的連接配接與調試
實作FPGA與ESP8266的連接配接與調試

再将上述的ESP8266子產品和USB轉序列槽子產品互相連接配接,進行燒錄固件。

注意 VCC接USB轉序列槽上的3.3v,将IO_0接地,将RST也要連接配接,在燒錄過程中,将RST接地複位一下,然後斷開,這樣才能燒錄成功。(具體也可能不需要複位也可以燒入成功)。

在燒入成功後就可以通過序列槽調試助手對ESP8266進行配置了。将其配置為TCP server。還要保持重新上電後仍可直接傳輸資料。波特率為115200.

實作FPGA與ESP8266的連接配接與調試

這是配置的AT指令設定。對此ESP8266的配置就暫時完成了。接下來就是将FPGA開發闆生成的資料如何通過ESP8266傳輸到網絡調試助手。

設計UART的tx子產品即可,将tx輸出端口與ESP8266上的rx連接配接即可。ESP8266上的3.3v與開發闆上的3.3v電源連接配接,接地與接地連接配接。

module uart_tx(
	input clk,
	input rst_n,
//	input [7:0] i_data,
//	input start,
	output reg rs232_tx
);


reg [7:0] cnt;
reg en;
reg start;
always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		cnt <= 8'd0;
		start <= 1'b0;
	end
	else if((en ==1'b0) && (start == 1'b0)) begin
		cnt <= cnt + 1'b1;
		start <= 1'b1;
	end
	else begin
		start <= 1'b0;
	end
end



reg [7:0] tx_data;
always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		tx_data <= 8'b0;
	end
	else if(start) begin
		tx_data <= cnt;
	end
end





reg [3:0] num;

always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		en <= 1'b0;
	end
	else if(start) begin
		en <= 1'b1;
	end
	else if(num==4'd11) begin
		en <= 1'b0;
	end
end

//---------------------------------波特率 115200----
reg [8:0] cnt_bps;
always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		cnt_bps <= 9'd0;
	end
	else if((cnt_bps==9'd433) || (en==1'b0)) begin
		cnt_bps <= 9'd0;
	end
	else begin
		cnt_bps <= cnt_bps + 1'b1;
	end
end

reg clk_bps;
always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		clk_bps <= 1'b0;
	end
	else if(cnt_bps==9'd216) begin
		clk_bps <= 1'b1;
	end
	else begin
		clk_bps <= 1'b0;
	end
end


always @ (posedge clk or negedge rst_n) begin
	if(!rst_n) begin
		num <= 4'd0;
		rs232_tx <= 1'b1;
	end
	else if(en) begin
		if(clk_bps) begin
			num <= num + 1'b1;
			case(num)
				4'd0 : rs232_tx <= 1'b0;
				4'd1 : rs232_tx <= tx_data[0];
				4'd2 : rs232_tx <= tx_data[1];
				4'd3 : rs232_tx <= tx_data[2];
				4'd4 : rs232_tx <= tx_data[3];
				4'd5 : rs232_tx <= tx_data[4];
				4'd6 : rs232_tx <= tx_data[5];
				4'd7 : rs232_tx <= tx_data[6];
				4'd8 : rs232_tx <= tx_data[7];
				4'd9 : rs232_tx <= 1'b1;
				default : rs232_tx <= 1'b1;
			endcase
		end
		else if(num==4'd11) begin
			num <= 4'd0;
		end
	end
end

endmodule

           

測試代碼

`timescale 1ps/1ps
module tb();
reg clk;
reg rst_n;
wire rs232_tx;

uart_tx uart_tx_inst(
	.clk(clk),
	.rst_n(rst_n),
	.rs232_tx(rs232_tx)
);

initial begin
	clk = 0;
	rst_n = 0;
	#22;
	rst_n = 1;
end

always #5 clk = ~clk;



endmodule

           

通過signal tap進行闆級調試采集到資料如圖:

實作FPGA與ESP8266的連接配接與調試
實作FPGA與ESP8266的連接配接與調試

對此,該子產品的設計就可以暫停一段時間了,現在的問題就是如何将網絡傳輸助手接收到的資料儲存到一個excel表中,或者其他檔案中。在網絡調試助手中設定的接收轉向檔案,發現并沒有儲存到資料。

接下來就是解決這個問題,為此打算使用matlab或者别的方法解決這個問題。