极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13075|回复: 0

Arduino的FreeRtos相关问题,,求助

[复制链接]
发表于 2018-4-3 12:01:56 | 显示全部楼层 |阅读模式
在FreeRtos中创建一个新任务TaskJsonRecive时,
只要执行到JsonObject& root = jsonBuffer.parseObject(json);   
就会使整个系统卡死,无反应,
求大神讲解
下面试该任务代码:
void TaskJsonRecive( void *pvParameters __attribute__((unused)) )  // This is a Task.
{
  
  for (;;)
  {
    // read the input on analog pin 0:
    //int sensorValue = analogRead(A0);
    // See if we can obtain or "Take" the Serial Semaphore.
    // If the semaphore is not available, wait 5 ticks of the Scheduler to see if it becomes free.
    if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
    {
      // We were able to obtain or "Take" the semaphore and can now access the shared resource.
      // We want to have the Serial Port for us alone, as it takes some time to print,
      // so we don't want it getting stolen during the middle of a conversion.
      // print out the value you read:
      //Serial.println(sensorValue);
      if (Serial.available() > 0) {
      delay(200);
      numdata = Serial.readBytes(json, 99);
      StaticJsonBuffer<400> jsonBuffer;
      
      JsonObject& root = jsonBuffer.parseObject(json);  ///逐步排查是这句代码有问题,,但不知道如何处理
      
      if (!root.success()) {
      Serial.println("parseObject() failed");
      Serial.println("END");
      return;
      }
      const char* sensor = root["sensor"];
      const char* go = root["go"];
      Serial.println(sensor);
      Serial.println(go);
      }
   
     while (Serial.read() >= 0){
        for (int i = 0; i < 99; i++) {
          json[i] = '\0';
        }
     }  //清空串口缓存  

      xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
    }

    vTaskDelay(67);  // one tick delay (15ms) in between reads for stability
  }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 00:17 , Processed in 0.039560 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表