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**** 2540720 points
Other Parts Discussed in Thread: CC2340R5

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

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1353331/cc2340r5-cc2340r5-uart-read-not-working

器件型号:CC2340R5

您好!  

我将使用 CC2340R5 simplelink_lowpower_f3_sdk_7_40_00_64示例代码 basic_ble。

我正在使用外设模式与 APK 建立连接。 每当 APK 向 BLE 发送任何请求时、针对该请求、我需要将相同的请求写入与 BLE 的 UART 相连的控制器以进行响应。  

控制器随后针对同一请求发送响应。  

目前、我可以通过 UART_2向控制器发送请求、但无法读取 UART_2上发送的响应。  

以下是我的 UART 配置代码:  

1)这是我创建的 UART 初始化位置的线程。 (我从 Resource Explorer 中给出的示例代码 uart2callback 中获取参考。)

void mainThread()
{
    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_CALLBACK;
    uartParams.readCallback = callbackFxn;
    uartParams.baudRate     = 115200;

    uart_handle = UART2_open(CONFIG_DISPLAY_UART, &uartParams);
}

2)这是回调函数。 不执行任何操作。

void callbackFxn(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
    if (status != UART2_STATUS_SUCCESS)
    {
        /* RX error occured in UART2_read() */
       // while (1) {}
    }

    numBytesRead = count;
   // sem_post(&sem);
}

3) uart_handle 取全局。 我从 APK 中获取请求的位置调用这两个函数。  

        UART2_write(uart_handle, newValue, len, NULL);
        UART2_read(uart_handle, newValue, sizeof(newValue), NULL);

在这里、UART 写入工作正常。 我在 UART 上得到的是准确的数据、但在读取时却找不到任何数据。  

我已经禁用了 Menu_start()函数;

我在这里缺少什么吗?  

此致、

Rushikesh。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的  Rushikesh:

    感谢您获得支持、

    几点我注意到、我看到您的主线程正在终止、您是否可以尝试添加具有延迟的无限循环?

    此外、UART 的操作模式是回调模式、但您不使用回调函数、我建议尝试阻塞模式或非阻塞模式、请在 uart2驱动程序 UART2.h 文件参考(TI.com)中找到更多信息

    希望这对您有所帮助、

    丹桂语

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、Tanguy、

    感谢您的建议。  

    根据您的建议进行了以下更改、并且效果很好!

    1)我已将 UART 工作模式设置为 UART2_Mode_Blocking。  

      uartParams.readMode   = UART2_Mode_Blocking;

    2)此外,我将调用 mainthread();每当有 APK 对 Characteristic 属性的请求时,我都会调用它。  

    并在将数据读入缓冲区后关闭 UART。

            mainThread();
            len = strlen(newValue);
    
            /* Pass NULL for bytesWritten since it's not used in this example */
            UART2_write(uart_handle, newValue, len, NULL);
            memset(newValue,0,sizeof(newValue));
            status = UART2_read(uart_handle, newValue, sizeof(newValue), NULL);
    
            UART2_close(uart_handle);
     

    如果有任何可以修改或优化的内容、向我提供建议。  

    此致、

    Rushikesh。