学前班
最后登录1970-1-1
在线时间 小时
注册时间2016-7-24
|
本帖最后由 yenhgng001 于 2016-10-20 17:49 编辑
本小白在把ESP8266放进FreeRTOS时遇到了一些小问题,找了很久就是找不到问题出在哪里
以下是main函数
- int main(void)
- {
- LED_Init();
- USART1_Init();
- ESP8266_Init();
-
- xTaskCreate(vTask_LED_RED ,"Task LED RED" ,100 ,NULL,2,NULL);
- xTaskCreate(vTask_LED_BLUE ,"Task LED BLUE" ,100 ,NULL,1,NULL);
- xTaskCreate(vTask_ESP8266_Test,"Task ESP8266 Test",1000,NULL,3,NULL);
-
- vTaskStartScheduler();
- }
复制代码
在不运行第三个ESP8266的任务的情况下,前两个LED任务完全没问题
以下是vTask_ESP8266_Test()函数
- void vTask_ESP8266_Test(void *vParameters){
- char* respond;
- ESP8266_Start();
-
- while(1){
- ESP8266_SendString ( ENABLE, "GET http://baidu.com HTTP/1.0\r\n\r\n\r\n", 0, Single_ID_0 );
- printf("Send GET Request Done!\n");
- respond = ESP8266_ReceiveString(ENABLE);
- printf("%s",respond);
- vTaskDelay(5000/portTICK_RATE_MS);
- }
- }<div>
- </div>
复制代码 ESP8266是按照野火裸机例程写的
这是ESP8266_Start()函数
- void ESP8266_Start(){
-
- printf ( "\r\n正在配置 ESP8266 ......\r\n" );
-
- ESP8266_CH_ENABLE();
-
- #if DEBUG
- printf("CH Enable Done!\n");
- #endif
-
- ESP8266_AT_Test ();
-
- #if DEBUG
- printf("AT Test Done!\n");
- #endif
-
- ESP8266_Net_Mode_Choose ( STA );
-
- #if DEBUG
- printf("Choose STA Net Mode Done!\n");
- #endif
- while ( ! ESP8266_JoinAP ( AP_SSID, AP_PASSWORD ) );
-
- #if DEBUG
- printf("Join AP Done!\n");
- #endif
-
- ESP8266_Enable_MultipleId ( DISABLE );
-
- #if DEBUG
- printf("Disable MultipleId Done!\n");
- #endif
-
- while ( ! ESP8266_Link_Server ( enumTCP, TcpServer_IP, TcpServer_Port, Single_ID_0 ) );
-
- #if DEBUG
- printf("Link Server Done!\n");
- #endif
-
- while ( ! ESP8266_UnvarnishSend () );
-
- #if DEBUG
- printf("Start UnvarnishSend Done!");
- #endif
-
- printf ( "\r\n配置 ESP8266完毕\r\n" );
- }
复制代码
下面是中断函数
- void USART3_IRQHandler ( void )
- {
- uint8_t ucCh;
-
- if ( USART_GetITStatus ( ESP8266_USARTx, USART_IT_RXNE ) == SET )
- {
- ucCh = USART_ReceiveData( ESP8266_USARTx );
-
- if ( strEsp8266_Fram_Record .InfBit .FramLength < ( RX_BUF_MAX_LEN - 1 ) )
- strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ++ ] = ucCh;
- }
-
- if ( USART_GetITStatus( ESP8266_USARTx, USART_IT_IDLE ) == SET )
- {
- strEsp8266_Fram_Record .InfBit .FramFinishFlag = 1;
-
- ucCh = USART_ReceiveData( ESP8266_USARTx );
-
- ucTcpClosedFlag = strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "CLOSED\r\n" ) ? 1 : 0;
- }
- }
复制代码
程序运行后一直到vTask_ESP8266_Test()函数的while循环里就开始出问题了,第一次发送GET请求是没有问题的,也能接收到响应,但是第二次就会卡住,连LED的也不闪了,好像整个系统都卡住了
下面是LED的任务
- void vTask_LED_RED(void *vParameters){
- while(1){
- LED_Switch(LED_RED,TURN_OFF);
- printf("LED_RED is OFF\n");
- vTaskDelay(1000/portTICK_RATE_MS); //Delay 1 sec
- LED_Switch(LED_RED,TURN_ON);
- printf("LED_RED is ON\n");
- vTaskDelay(1000/portTICK_RATE_MS);
- }
- }
- void vTask_LED_BLUE(void *vParameters){
- while(1){
- LED_Switch(LED_BLUE,TURN_ON);
- printf("LED_BLUE is ON\n");
- vTaskDelay(1000/portTICK_RATE_MS);
- LED_Switch(LED_BLUE,TURN_OFF);
- printf("LED_BLUE is OFF\n");
- vTaskDelay(1000/portTICK_RATE_MS);
- }
- }
复制代码
下面是串口打印的数据
- 正在配置 ESP8266 ......
- CH Enable Done!
- LED_RED is OFF
- LED_BLUE is ON
- LED_RED is ON
- LED_BLUE is OFF
- AT Test Done!
- LED_RED is OFF
- LED_BLUE is ON
- LED_RED is ON
- LED_BLUE is OFF
- Choose STA Net Mode Done!
- LED_RED is OFF
- ....... //这里各种 ON 和 OFF最多,可能是加入AP比较耗时间
- LED_BLUE is OFF
- Join AP Done!
- LED_RED is OFF
- LED_BLUE is ON
- Disable MultipleId Done!
- LED_RED is ON
- LED_BLUE is OFF
- LED_RED is OFF
- LED_BLUE is ON
- LED_RED is ON
- LED_BLUE is OFF
- LED_RED is OFF
- LED_BLUE is ON
- Link Server Done!
- LED_RED is ON
- LED_BLUE is OFF
- Start UnvarnishSend Done!
- 配置 ESP8266 完毕
- Send GET Request Done!
- Recive Function In!
- Recive Function set Done! //第一次就没问题
- Recive Function while Done!
- add \0 Done!
- Recive Function Finished!
- CLOSED
- HTTP/1.1 200 OK
- Server: nginx
- Date: Thu, 20 Oct 2016 09:44:46 GMT
- Content-Type: text/html
- Content-Length: 163
- Last-Modified: Thu, 25 Jun 2015 03:08:19 GMT
- Connection: close
- Accept-Ranges: bytes
- <html>
- <head>
- <meta http-equiv="refresh" content="0; url=http://hndnserror7.wo.com.cn:8080/sj/index.html" />
- </head
- <body>
- </body>
- </html>
- LED_RED is OFF
- LED_BLUE is ON
- LED_RED is ON
- LED_BLUE is OFF
- LED_RED is OFF
- LED_BLUE is ON
- LED_RED is ON
- LED_BLUE is OFF
- LED_RED is OFF
- LED_BLUE is ON
- Send GET Request Done!
- Recive Function In!
- Recive Function set Done! //问题就出在这了,这是第二次发送
复制代码
Recive Function In!
Recive Function set Done!这几句是在char * ESP8266_ReceiveString ( FunctionalState enumEnUnvarnishTx )函数里
- char * ESP8266_ReceiveString ( FunctionalState enumEnUnvarnishTx ){
-
- char * pRecStr = 0;
-
- printf("Recive Function In!\n");
-
- strEsp8266_Fram_Record .InfBit .FramLength = 0;
- strEsp8266_Fram_Record .InfBit .FramFinishFlag = 0;
-
- printf("Recive Function set Done!\n");
-
- while ( ! strEsp8266_Fram_Record .InfBit .FramFinishFlag );
- printf("Recive Function while Done!\n");
- strEsp8266_Fram_Record .Data_RX_BUF [ strEsp8266_Fram_Record .InfBit .FramLength ] = '\0';
- printf("add \\0 Done!\n");
-
- if ( enumEnUnvarnishTx )
- pRecStr = strEsp8266_Fram_Record .Data_RX_BUF;
- else
- {
- if ( strstr ( strEsp8266_Fram_Record .Data_RX_BUF, "+IPD" ) )
- pRecStr = strEsp8266_Fram_Record .Data_RX_BUF;
- }
- printf("Recive Function Finished!\n");
- return pRecStr;
- }
复制代码
|
|