目录
资料下载地址:基于STM32无线抄表系统
一、项目描述
1.通过串口获取电表数据,并在OLED液晶上显示;
2. 通过ESP8266WIFI模块将电表数据上传到云平台和手机APP上
二、原理图
三、实物
手机APP
云平台
四、代码
ESP8266代码
#include "bsp_esp8266.h"
#include "common.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "bsp_SysTick.h"
#include "test.h"
#include "bsp_usart1.h"
/*
管脚连接关系
ESP8266 单片机
VCC ---------- 5V
GND ---------- GND
TXD ---------- PB11 (RX)
RXD ---------- PB10 (TX)
RST ---------- PA8 (可以不连接)
IO_0 ---------- 未连接
模块的 RST引脚和IO_0引脚 默认为高电平, 所以RST引脚不连接也可以正常使用。
模块必须5V供电,3.3V供电时不能正常工作。
*/
static void ESP8266_GPIO_Config ( void );
static void ESP8266_USART_Config ( void );
static void ESP8266_USART_NVIC_Configuration ( void );
struct STRUCT_USARTx_Fram strEsp8266_Fram_Record = { 0 }; //ESP8266接收数据结构体
/**
* @brief ESP8266初始化函数
* @param 无
* @retval 无
*/
void ESP8266_Init ( void )
{
ESP8266_GPIO_Config (); //ESP8266模块使用到的IO口初始化
ESP8266_USART_Config (); //与ESP8266模块连接的串口初始化
macESP8266_RST_HIGH_LEVEL(); //ESP8266模块 复位脚设置为高电平
macESP8266_CH_DISABLE(); //片选引脚不选中
}
/**
* @brief 初始化ESP8266用到的GPIO引脚
* @param 无
* @retval 无
*/
static void ESP8266_GPIO_Config ( void )
{
/*定义一个GPIO_InitTypeDef类型的结构体*/
GPIO_InitTypeDef GPIO_InitStructure;
/* 配置 CH_PD 引脚*/
macESP8266_CH_PD_APBxClock_FUN ( macESP8266_CH_PD_CLK, ENABLE );
GPIO_InitStructure.GPIO_Pin = macESP8266_CH_PD_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init ( macESP8266_CH_PD_PORT, & GPIO_InitStructure );
/* 配置 RST 引脚*/
macESP8266_RST_APBxClock_FUN ( macESP8266_RST_CLK, ENABLE );
GPIO_InitStructure.GPIO_Pin = macESP8266_RST_PIN;
GPIO_Init ( macESP8266_RST_PORT, & GPIO_InitStructure );
}
/**
* @brief 初始化ESP8266用到的 USART
* @param 无
* @retval 无
*/
static void ESP8266_USART_Config ( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* config USART clock */
macESP8266_USART_APBxClock_FUN ( macESP8266_USART_CLK, ENABLE );
macESP8266_USART_GPIO_APBxClock_FUN ( macESP8266_USART_GPIO_CLK, ENABLE );
/* USART GPIO config */
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = macESP8266_USART_TX_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init( macESP8266_USART_TX_PORT