This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC2340R5:CC2340R5:UART 回调功能不工作。

Guru**** 1456740 points
Other Parts Discussed in Thread: CC2340R5
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1355557/cc2340r5-cc2340r5-uart-callback-not-working-properly

器件型号:CC2340R5

您好!  

我将使用 CC2340R5 SDK 版本7.40 basic_ble 工程。

我将在 UART_2上读取和写入数据。 我最初正在通过 UART 从 MCU 向 BLE 发送命令、但如果 BLE 已断开连接/处于广播模式、则 UART 回调函数不会触发。  

在读取回调函数时、它仅在我与 Android 应用建立外设连接时触发。

同样在外设中、回调并不总是触发。 它有时会错过回调。 不过、我从 UART 上获取数据。  

下面是我的代码:  

UART 配置:  

void *mainThread(void *arg0)
{
    char input;
    const char echoPrompt[] = "Echoing characters:\r\n";
    UART2_Params uartParams;
    int32_t semStatus;
    uint32_t status = UART2_STATUS_SUCCESS;
    uint8_t tempbuf[64] = {0};

    /* Create semaphore */
 //   semStatus = sem_init(&sem, 0, 0);

//    if (semStatus != 0)
//    {
//        /* Error creating semaphore */
//        // while (1) {}
//    }

    /* Create a UART in CALLBACK read mode */
    UART2_Params_init(&uartParams);
    uartParams.readMode     = UART2_Mode_BLOCKING;
    uartParams.writeMode    = UART2_Mode_BLOCKING;
    uartParams.readCallback = callbackFxn;
    uartParams.baudRate     = 115200;
//    uartParams.readReturnMode = UART2_ReadReturnMode_PARTIAL;
    uartParams.dataLength = UART2_DataLen_8;


    uart_handle = UART2_open(CONFIG_DISPLAY_UART, &uartParams);
    
}

UART 回调:  

void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
   // uint8_t tempbuf[260] = {0};

    if (status != UART2_STATUS_SUCCESS)
    {
        /* RX error occured in UART2_read() */
       // while (1) {}
    }

    status = UART2_read(uart_handle, buffer, sizeof(count), NULL);

    BLE_MCU_Cmd_parser(buffer);
}

在 main()函数中调用:  

int main()
{
    pthread_t thread;
    pthread_attr_t attrs;
    struct sched_param priParam;
    int retc;

  /* Register Application callback to trap asserts raised in the Stack */
  halAssertCback = AssertHandler;
  RegisterAssertCback(AssertHandler);

  Board_init();

  /* Initialize the attributes structure with default values */
  pthread_attr_init(&attrs);

  /* Set priority, detach state, and stack size attributes */
  priParam.sched_priority = 1;
  retc                    = pthread_attr_setschedparam(&attrs, &priParam);
  retc |= pthread_attr_setdetachstate(&attrs, PTHREAD_CREATE_DETACHED);
  retc |= pthread_attr_setstacksize(&attrs, THREADSTACKSIZE);
  if (retc != 0)
  {
      /* failed to set attributes */
    //  while (1) {}
  }

  retc = pthread_create(&thread, &attrs, mainThread, NULL);
  if (retc != 0)
  {
      /* pthread_create() failed */
     // while (1) {}
  }

  /* Update User Configuration of the stack */
  user0Cfg.appServiceInfo->timerTickPeriod = ICall_getTickPeriod();
  user0Cfg.appServiceInfo->timerMaxMillisecond  = ICall_getMaxMSecs();

  /* Initialize all applications tasks */
  appMain();

  /* Start the FreeRTOS scheduler */
  vTaskStartScheduler();

  return 0;

}