初级会员
- 积分
- 142
- 金钱
- 142
- 注册时间
- 2018-3-29
- 在线时间
- 17 小时
|
1金钱
买了块ATK-esp8266 WiFi模块,在stm32中写程序去初始化模块,程序调用了原子哥的两个函数,初始化程序是自己写的,连接上之后,LCD屏上一直显示No Esp8266 was find!,下面附上程序,望大佬能给看一下。
u8* esp8266_check_cmd(u8 *str)
{
char *strx=0;
if(USART_RX_STA&0X8000) //½ÓÊÕµ½Ò»´ÎÊý¾ÝÁË
{
USART_RX_BUF[USART_RX_STA&0X7FFF]=0;//Ìí¼Ó½áÊø·û
strx=strstr((const char*)USART_RX_BUF,(const char*)str);
}
return (u8*)strx;
}
u8 esp8266_send_cmd(u8 *cmd,u8 *ack,u16 waittime)
{
u8 res=0;
USART_RX_STA=0;
printf("%s\r\n",cmd); //·¢ËÍÃüÁî
if(ack&&waittime) //ÐèÒªµÈ´ýÓ¦´ð
{
while(--waittime) //µÈ´ýµ¹¼Æʱ
{
delay_ms(10);
if(USART_RX_STA&0X8000)//½ÓÊÕµ½ÆÚ´ýµÄÓ¦´ð½á¹û
{
if(esp8266_check_cmd(ack))
{
// printf("ack:%s\r\n",(u8*)ack);
break;
}
USART_RX_STA=0;
}
}
if(waittime==0)res=1;
}
return res;
}
u8 esp8266_send_data(u8 *data,u8 *ack,u16 waittime)
{
u8 res=0;
USART_RX_STA=0;
printf("%s",data); //·¢ËÍÊý¾Ý
if(ack&&waittime) //ÐèÒªµÈ´ýÓ¦´ð
{
while(--waittime) //µÈ´ýµ¹¼Æʱ
{
delay_ms(10);
if(USART_RX_STA&0X8000)//½ÓÊÕµ½ÆÚ´ýµÄÓ¦´ð½á¹û
{
if(esp8266_check_cmd(ack))break;//µÃµ½ÓÐЧÊý¾Ý
USART_RX_STA=0;
}
}
if(waittime==0)res=1;
}
return res;
}
//ESP8266初始化程序
void esp8266_init()
{
while(esp8266_send_cmd("AT","OK",20))//¼ì²éWIFIÄ£¿éÊÇ·ñÔÚÏß
{
LCD_ShowString(30,60,209,16,16,"No Esp8266 was find!");
delay_ms(500);
LCD_Fill(30,60,209,60+16,WHITE);
LCD_ShowString(30,60,209,16,16,"Try reconnecting...");
}
while(esp8266_send_cmd("AT+CWMODE=2","OK",20)) //WIFIÄ£¿éģʽÉèÖÃ
{
LCD_ShowString(30,80,209,16,16,"Mode setting failed!");
}LCD_ShowString(30,80,209,16,16,"Mode setting OK");
while(esp8266_send_cmd("AT+RST","",20)) //WIFIÄ£¿éÖØÆô
{
LCD_ShowString(30,100,209,16,16,"esp8266 restart failure!");
}LCD_ShowString(30,100,209,16,16,"esp8266 restart OK");
while(esp8266_send_cmd("AT+CWSAP=\"Graduation_pro-LY\",\"12345678\",1,4","OK",20)) //WIFIÄ£¿é¿ªÆôÈȵ㠣¨WiFiÃû ÃÜÂë ͨµÀºÅ ¼ÓÃÜ·½Ê½WPA_WPA2_PSK£©
{
LCD_ShowString(30,120,209,16,16,"WiFi setting failed!");
}LCD_ShowString(30,120,209,16,16,"WiFi setting OK");
esp8266_send_cmd("AT+CIPMUX=1","",0); //0: µ¥Á¬½Ó 1£º¿ªÆô¶àÁ¬½Ó
while(esp8266_send_cmd("AT+CIPSERVER=1,8086","OK",20)) //serverģʽ ¶Ë¿Ú£º8086
{
LCD_ShowString(30,140,209,16,16,"ESP8266 init failed!");
}LCD_ShowString(30,140,209,16,16,"ESP8266 init OK");
}
|
|