基于FPGA的ESP8266无线数据传输(温湿度DTH11、光照强度BH1750、WIFI模块)连接中国移动onenet云平台,仿真+上板

文章目录

一、创建云平台产品设备


使用串口助手测试传输过程

相关信息记录

二、FPGA仿真WIFI模块通信过程

仿真分析

c 复制代码
 //各个状态tx_data
    always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        uart_tx_data <= 8'd0;
    end
    else if((state==AT) && tx_count<8'd6 ) begin
        uart_tx_data <= cmd_AT[47 - tx_count *8 -:8];
    end
    else if((state==CWMODE) && tx_count<8'd15 ) begin
        uart_tx_data <= cmd_CWMODE[119 - tx_count *8 -:8];
    end
    else if((state==RST) && tx_count<8'd10 ) begin
        uart_tx_data <= cmd_RST[79 - tx_count *8 -:8];
    end
    else if((state==CWJAP) && tx_count<8'd31 ) begin
        uart_tx_data <= cmd_CWJAP[247 - tx_count *8 -:8];
    end
    else if((state==CWDHCP) && tx_count<8'd17 ) begin
        uart_tx_data <= cmd_CWDHCP[135 - tx_count *8 -:8];
    end
    else if((state==MQTTUSERCFG) && tx_count<8'd172 ) begin
        uart_tx_data <= cmd_MQTTUSERCFG[1375 - tx_count *8 -:8];
    end
    else if((state==MQTTCONN) && tx_count<8'd45 ) begin
        uart_tx_data <= cmd_MQTTCONN[359 - tx_count *8 -:8];
    end
    else if((state==MQTTSUB) && tx_count<8'd67 ) begin
        uart_tx_data <= cmd_MQTTSUB[535 - tx_count *8 -:8];
    end
    else if((state==MQTTPUB) && tx_count<8'd123 ) begin
        uart_tx_data <= cmd_MQTTPUB[983 - tx_count *8 -:8];
    end
    else begin
        uart_tx_data <= uart_tx_data;
    end
end
c 复制代码
always @(posedge clk or negedge rst_n) begin
    if(!rst_n) begin
        state <= IDLE;
    end
    else begin
    case(state)
        IDLE:begin
               state<=AT;
        end
        AT:begin//at test
            if(tx_count==8'd6)begin
                state <= WAK_AT;
            end
            else begin
                state <= AT;
            end
        end
        WAK_AT:begin
            if(rx_count==8'd2)begin
                state <= CWMODE;
            end
            else begin
                state <= WAK_AT;
            end
        end
        CWMODE:begin//set mode
            if(tx_count==8'd15)begin
                state <= WAK_CWMODE;
            end
            else begin
                state <= CWMODE;
            end
        end
        WAK_CWMODE:begin
            if(rx_count==8'd2)begin
                state <= RST;
            end
            else begin
                state <= WAK_CWMODE;
            end
        end
        RST:begin//at rst
            if(tx_count==8'd10)begin
                state <= WAK_RST;
            end
            else begin
                state <= RST;
            end
        end
        WAK_RST:begin
            if(rx_count==8'd2)begin
                state <= CWJAP;
            end
            else begin
                state <= WAK_RST;
            end
        end
        CWJAP:begin//at rst
            if(tx_count==8'd31)begin
                state <= WAK_CWJAP;
            end
            else begin
                state <= CWJAP;
            end
        end
        WAK_CWJAP:begin//at rst
            if(rx_count==8'd2)begin
                state <= CWDHCP;
            end
            else begin
                state <= WAK_CWJAP;
            end
        end
        CWDHCP:begin//at rst
            if(tx_count==8'd17)begin
                state <= WAK_CWDHCP;
            end
            else begin
                state <= CWDHCP;
            end
        end
        WAK_CWDHCP:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTUSERCFG;
            end
            else begin
                state <= WAK_CWDHCP;
            end
        end
        MQTTUSERCFG:begin//at rst
            if(tx_count==8'd172)begin
                state <= WAK_MQTTUSERCFG;
            end
            else begin
                state <= MQTTUSERCFG;
            end
        end
        WAK_MQTTUSERCFG:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTCONN;
            end
            else begin
                state <= WAK_MQTTUSERCFG;
            end
        end
        MQTTCONN:begin//at rst
            if(tx_count==8'd45)begin
                state <= WAK_MQTTCONN;
            end
            else begin
                state <= MQTTCONN;
            end
        end
        WAK_MQTTCONN:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTSUB;
            end
            else begin
                state <= WAK_MQTTCONN;
            end
        end
        MQTTSUB:begin//at rst
            if(tx_count==8'd67)begin
                state <= WAK_MQTTSUB;
            end
            else begin
                state <= MQTTSUB;
            end
        end
        WAK_MQTTSUB:begin//at rst
            if(rx_count==8'd2)begin
                state <= MQTTPUB;
            end
            else begin
                state <= WAK_MQTTSUB;
            end
        end
        MQTTPUB:begin//at rst
            if(tx_count==8'd123)begin
                state <= WAK_MQTTPUB;
            end
            else begin
                state <= MQTTPUB;
            end
        end
        WAK_MQTTPUB:begin//at rst
            if(rx_count==8'd2)begin
                state <= IDLE;
            end
            else begin
                state <= WAK_MQTTPUB;
            end
        end
        
        
        default:state <= IDLE;
        endcase
    end
    end

接收数据判断只是简单做了一下,因为是正确回应的话所有的指令最后都是OK。所以可以一直缓存16位数据,当持续时间大于串口接受结束标志之间的间隔后进行判断,如果最后接收到的缓存16位数据是"OK",则进入下一个状态即可,仿真只是检验一下过程,没做这一块。

按照第一部分设置的AT指令进行发送,主要就是一个状态机,一个是数据缓存发送。

2.上板

买的模块还没到,等到了再加上这部分内容。


总结

持续更新...

相关推荐
FPGA之旅9 小时前
FPGA从零到一实现FOC(一)之PWM模块设计
fpga开发·dubbo
XMAIPC_Robot10 小时前
基于ARM+FPGA的光栅尺精密位移加速度测试解决方案
arm开发·人工智能·fpga开发·自动化·边缘计算
cycf11 小时前
状态机的设计
fpga开发
szxinmai主板定制专家13 小时前
【精密测量】基于ARM+FPGA的多路光栅信号采集方案
服务器·arm开发·人工智能·嵌入式硬件·fpga开发
千宇宙航20 小时前
闲庭信步使用SV搭建图像测试平台:第三十二课——系列结篇语
fpga开发
千宇宙航1 天前
闲庭信步使用SV搭建图像测试平台:第三十一课——基于神经网络的手写数字识别
图像处理·人工智能·深度学习·神经网络·计算机视觉·fpga开发
小眼睛FPGA2 天前
【RK3568+PG2L50H开发板实验例程】FPGA部分/紫光同创 IP core 的使用及添加
科技·嵌入式硬件·ai·fpga开发·gpu算力
forgeda2 天前
如何将FPGA设计验证效率提升1000倍以上(2)
fpga开发·前沿技术·在线调试·硬件断点·时钟断点·事件断点
9527华安2 天前
FPGA实现40G网卡NIC,基于PCIE4C+40G/50G Ethernet subsystem架构,提供工程源码和技术支持
fpga开发·架构·网卡·ethernet·nic·40g·pcie4c
search72 天前
写Verilog 的环境:逻辑综合、逻辑仿真
fpga开发