一个esp8266模块连接到电脑设置成server,另一个esp8266模块连接到mini板上,已经可以通过单片机同server建立连接,单片机也可以向server发送数据,就是单片机不能接收从server发来的数据,通过调用watch window发现USART_RX_BUFF最后一次是AT+CIPMODE=1
OK
,不是server发送给单片机的数据,说明单片机根本没接收到server的数据,还有个问题是,怎么确定数据是从server发来的你想要的数据还是esp8266回复你发送的命令的数据?[mw_shl_code=c,true]void atk_8266_init(void)
{
u8 ipbuf[32]="192.168.4.1"; //IP»o′æ
u8 *p;
u8 res=0;
u16 rlen=0;
p=mymalloc(32); //éêÇë32×Ö½úÄú′æ
atk_8266_send_cmd("AT+CWMODE=1","OK",50); //éèÖÃWIFI STAÄ£ê½
atk_8266_send_cmd("AT+RST","OK",50); //DHCP·tÎñÆ÷1رÕ(½öAPÄ£ê½óDD§)
//delay_ms(1000); //Ñóê±4Sμè′yÖØÆô3é1|
//delay_ms(1000);
//delay_ms(1000);
//delay_ms(1000);
//éèÖÃᬽóμ½μÄWIFIíøÂçÃû3Æ/¼óÃü·½ê½/ÃüÂë,Õa¼¸¸ö2ÎêyDèòa¸ù¾YÄú×Ô¼oμÄ·óéÆ÷éèÖýøDDDT¸Ä!!
sprintf((char*)p,"AT+CWJAP="%s","%s"",wifista_ssid,wifista_password);//éèÖÃÎTÏß2Îêy:ssid,ÃüÂë
while(atk_8266_send_cmd(p,"WIFI GOT IP",300)); //ᬽóÄ¿±ê·óéÆ÷,2¢Çò»ñμÃIP
atk_8266_send_cmd("AT+CIPMUX=0","OK",50); //0£oμ¥ᬽó£¬1£o¶àᬽó
sprintf((char*)p,"AT+CIPSTART="TCP","%s",%s",ipbuf,(u8*)portnum); //ÅäÖÃÄ¿±êTCP·tÎñÆ÷
while(atk_8266_send_cmd(p,"OK",200));
atk_8266_send_cmd("AT+CIPMODE=1","OK",200); //′«êäÄ£ê½Îa£oí¸′«
//atk_8266_send_cmd("AT+CIPSEND","OK",20); //¿aê¼í¸′«
//atk_8266_send_cmd("FF00FF","",20); //¿aê¼í¸′«
if(USART2_RX_STA&0X8000) //½óêÕμ½ò»′Îêy¾YáË
{
rlen=USART2_RX_STA&0X7FFF; //μÃμ½±¾′νóêÕμ½μÄêy¾Y3¤¶è
USART2_RX_BUF[rlen]=0; //ìí¼ó½áêø·û
//printf("%s",USART2_RX_BUF); //·¢Ëíμ½′®¿ú
UART_PutStr(USART1,(uint8_t*)USART2_RX_BUF);
if(strcmp((char*)USART2_RX_BUF,"AT+CIPMODE=1
OK
")==0) LED0=0;
else LED0=1;
USART2_RX_STA=0;
}
}[/mw_shl_code][mw_shl_code=c,true]void USART2_IRQHandler(void)
{
u8 res;
if(USART2->SR&(1<<5))//½óêÕμ½êy¾Y
{
res=USART2->DR;
if((USART2_RX_STA&(1<<15))==0) //»1¿éòÔ½óêÕêy¾Y
{
TIM4->CNT=0; //¼ÆêyÆ÷Çå¿Õ
if(USART2_RX_STA==0)TIM4_Set(1); //ê1Äü¶¨ê±Æ÷4μÄÖD¶Ï
USART2_RX_BUF[USART2_RX_STA++]=res; //¼Ç¼½óêÕμ½μÄÖμ
}else
{
USART2_RX_STA|=1<<15; //Ç¿ÖƱê¼Ç½óêÕíê3é
}
}
} [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>