STM(WIFI模块)
串口3变量是在main.c中自动生成的,要引入外部变量
wifi一定要初始化(不然导致无法使用)
WIFI输出口设置为输出(即PB8,PB9)
先测试WIFI是否正常
其次使用串口AT+CWSAP指令完成:AT+CWSAP=\"mywifi\",\"12345678\",1,3\r\n
AT+CWSAP=WIFI名称+WIFI密码\r\n+字节数(字节数一定要相对应)
#include "wifi.h"
#include "stm32f1xx_hal.h"
extern UART_HandleTypeDef huart3;
void wifi_init(){
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_9,1); //ʹÄÜ
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_8,1); //¸´Î»
}
//wifi²âÊÔ
void wifi_test(){
wifi_init();
HAL_Delay(500);
uint8_t rec[100];
HAL_UART_Transmit(&huart3,"AT\r\n",4,200); //\rÊÇ´ú±í»Ø³µ\nÊÇ´ú±í»»ÐÐ
HAL_UART_Receive(&huart3,rec,100,2000);
printf(rec);
}
//·¢³öWIFIÈȵã
void wifi_hotport(){
//´ò¿ªWIFIFÈȵã
wifi_init();
HAL_Delay(500);
uint8_t rec[100];
HAL_UART_Transmit(&huart3,"AT+CWSAP=\"mywifi\",\"12345678\",1,3\r\n",36,200); //\rÊÇ´ú±í»Ø³µ\nÊÇ´ú±í»»ÐÐ
HAL_UART_Receive(&huart3,rec,100,2000);
printf(rec);
}
定义的.c和.h文件的函数,要在主函数中调用