完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
宏定义都放头文件里了,打开工程文件可以看到,下面是些主要函数的声明 void ESP8266_Init ( void ); void ESP8266_Rst ( void ); bool ESP8266_Cmd ( char * cmd, char * reply1, char * reply2, u32 waittime ); void ESP8266_AT_Test ( void ); bool ESP8266_Net_Mode_Choose ( ENUM_Net_ModeTypeDef enumMode ); bool ESP8266_JoinAP ( char * pSSID, char * pPassWord ); bool ESP8266_BuildAP ( char * pSSID, char * pPassWord, ENUM_AP_PsdMode_TypeDef enunPsdMode ); bool ESP8266_Enable_MultipleId ( FunctionalState enumEnUnvarnishTx ); bool ESP8266_Link_Server ( ENUM_NetPro_TypeDef enumE, char * ip, char * ComNum, ENUM_ID_NO_TypeDef id); bool ESP8266_StartOrShutServer ( FunctionalState enumMode, char * pPortNum, char * pTimeOver ); uint8_t ESP8266_Get_LinkStatus ( void ); uint8_t ESP8266_Get_IdLinkStatus ( void ); uint8_t ESP8266_Inquire_ApIp ( char * pApIp, uint8_t ucArrayLength ); bool ESP8266_UnvarnishSend ( void ); void ESP8266_ExitUnvarnishSend ( void ); bool ESP8266_SendString ( FunctionalState enumEnUnvarnishTx, char * pStr, u32 ulStrLength, ENUM_ID_NO_TypeDef ucId ); char * ESP8266_ReceiveString ( FunctionalState enumEnUnvarnishTx ); uint8_t ESP8266_CWLIF ( char * pStaIp ); uint8_t ESP8266_CIPAP ( char * pApIp ); 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, &GPIO_InitStructure); /* Configure USART Rx as input floating */ GPIO_InitStructure.GPIO_Pin = macESP8266_USART_RX_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(macESP8266_USART_RX_PORT, &GPIO_InitStructure); /* USART1 mode config */ USART_InitStructure.USART_BaudRate = macESP8266_USART_BAUD_RATE; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No ; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(macESP8266_USARTx, &USART_InitStructure); /* 中断配置 */ USART_ITConfig ( macESP8266_USARTx, USART_IT_RXNE, ENABLE ); //使能串口接收中断 USART_ITConfig ( macESP8266_USARTx, USART_IT_IDLE, ENABLE ); //使能串口总线空闲中断 ESP8266_USART_NVIC_Configuration (); USART_Cmd(macESP8266_USARTx, ENABLE); } /** * @brief 配置 ESP8266 USART 的 NVIC 中断 * @param 无 * @retval 无 */ static void ESP8266_USART_NVIC_Configuration ( void ) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig ( macNVIC_PriorityGroup_x ); /* Enable the USART2 Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = macESP8266_USART_IRQ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } /* * 函数名:ESP8266_Rst * 描述 :重启WF-ESP8266模块 * 输入 :无 * 返回 : 无 * 调用 :被 ESP8266_AT_Test 调用 */ void ESP8266_Rst ( void ) { #if 0 ESP8266_Cmd ( "AT+RST", "OK", "ready", 2500 ); #else macESP8266_RST_LOW_LEVEL(); Delay_ms ( 500 ); macESP8266_RST_HIGH_LEVEL(); #endif } /* * 函数名:ESP8266_Cmd * 描述 :对WF-ESP8266模块发送AT指令 * 输入 :cmd,待发送的指令 * reply1,reply2,期待的响应,为NULL表不需响应,两者为或逻辑关系 * waittime,等待响应的时间 * 返回 : 1,指令发送成功 * 0,指令发送失败 * 调用 :被外部调用 */ bool ESP8266_Cmd ( char * cmd, char * reply1, char * reply2, u32 waittime ) { strEsp8266_Fram_Record .InfBit .FramLength = 0; //从新开始接收新的数据包 macESP8266_Usart ( "%srn", cmd ); if ( ( reply1 == 0 ) && ( reply2 == 0 ) ) //不需要接收数据 return true; Delay_ms ( waittime ); //延时 strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ] = ' |