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

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1464778/cc2340r5-debugging-uart-baud-rate-compatibility-issue-in-cc2340r5-central-peripheral-data-stream-communication

器件型号:CC2340R5

工具与软件:

我修改了 Data Stream Project 才能启用 外设+中心角色 并将其刷写到 CC2340R5器件中。 另一个 CC2340R5器件以外设角色运行未修改的数据流项目。 这两个器件都成功建立了 BLE 连接。

  • 115200波特率下的 UART 通信 :通过 UART (中央到外设)在设备之间传输和接收数据时运行完美。
  • 9600波特率下的 UART 通信 :经过几秒钟的连续数据传输和接收后 中央设备挂起 .

连接到 BLE 模块的终端设备仅支持 9600波特率 、使通信在该波特率下无缝工作至关重要。

中央设备设置和代码:

我附上了屏幕截图、其中显示:

  1. 的设置 中央设备 .
  2. 针对数据流服务特性的代码处理数据读取/写入操作。

需要紧急支持:

  1. 潜在的问题 :在高频数据传输过程中,中心设备的 UART 接口或缓冲区处理可能无法有效地处理较慢的波特率(9600)。
  2. 征求建议 :请建议修改代码、UART 配置或流控制机制以解决此问题。
    // Writing UART data to the peripheral from central device
    void sendUartToDataIn() {
        bStatus_t status = SUCCESS;
        uint16_t offset = 0;
        uint16_t mtuSize = 200;      
        uint16_t headerSize = 3;     // Approximate GATT header size
        uint16_t maxChunkSize = mtuSize - headerSize;
        uint16_t dataLength = BufferSize;//strlen((char*)uartReadBuffer);  // Total data length
        attWriteReq_t req;
        char buffer[40];
    
        // Loop until all data is sent
        while (offset < dataLength) {
            // Determine the chunk size for this iteration
            uint16_t chunkSize = (dataLength - offset > maxChunkSize) ? maxChunkSize : (dataLength - offset);
            bool chunkSent = false;
    
            // Retry sending the current chunk until successful
            while (!chunkSent) {
                // Allocate memory for the write request
                req.pValue = GATT_bm_alloc(0x0, ATT_WRITE_REQ, chunkSize, NULL);
                if (req.pValue != NULL) {
                    // Set up the request details
                    req.handle = 0x25;  // Set handle for DataIn characteristic
                    req.len = chunkSize;
                    req.sig = FALSE;
                    req.cmd = TRUE;  // Using Write Command (Write without Response)
    
                    // Copy data to the request buffer
                    memcpy(req.pValue, uartReadBuffer + offset, chunkSize);
    
                    // Attempt to send the data chunk
    //                vTaskDelay(pdMS_TO_TICKS(5));
                    status = GATT_WriteNoRsp(0x0, &req);
    //                vTaskDelay(pdMS_TO_TICKS(10));
    
                    if (status == SUCCESS) {
                        chunkSent = true;      // Exit retry loop on success
                        offset += chunkSize;   // Move to the next chunk
                        // Only clear sent chunk data in `uartReadBuffer` if desired, or keep it until the entire buffer is read
                    } else {
                        // Free the allocated buffer on failure
                        GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
                        vTaskDelay(pdMS_TO_TICKS(10));
                    }
                } else {
                    // Memory allocation failed; log error and retry after delay
                    UART2_write(uart, "Memory allocation failed\n", strlen("Memory allocation failed\n"), NULL);
                    vTaskDelay(pdMS_TO_TICKS(50));  // Delay before retrying allocation
                }
            }
        }
    
        // Reset UART read buffer for new data
        memset(uartReadBuffer, 0, UART_MAX_READ_SIZE);
        UART2_read(uart, uartReadBuffer, UART_MAX_READ_SIZE, NULL);  // Set up UART for the next data reception
    }
    
    
    
    // Reading data at central form peripheral and writing it to UART
     case ATT_HANDLE_VALUE_NOTI:
                {
                    // Handle incoming notification data
                    uint16_t handle = gattMsg->msg.handleValueNoti.handle;
                    uint8_t *pValue = gattMsg->msg.handleValueNoti.pValue;
                    uint16_t len = gattMsg->msg.handleValueNoti.len;
                    uint16_t bytesWritten = 0;
                    uint16_t chunkSize = 200;  // Define the max UART write size (200 bytes in this case)
    
    //                snprintf(buffer, sizeof(buffer), "Size : %d\n", len);
    //                UART2_write(uart, buffer, strlen(buffer), NULL);
    
                    // Loop to write data to UART in manageable chunks
                    while (bytesWritten < len) {
                        uint16_t bytesToWrite = (len - bytesWritten) > chunkSize ? chunkSize : (len - bytesWritten);
    
                        // Write a chunk to UART
                        UART2_write(uart, pValue + bytesWritten, bytesToWrite, NULL);
    //                    vTaskDelay(pdMS_TO_TICKS(5));
    
                        // Update the bytes written
                        bytesWritten += bytesToWrite;
                        GATT_bm_free(&gattMsg->msg,gattMsg->method);
    
                    }

感谢您的支持。

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

    您好、Aman、

    感谢您的咨询。 请提供以下帮助、以便更好地了解该问题:

    1. 您使用的 SDK 版本是什么?
    2. 什么器件导致崩溃/挂起、未修改的数据流(作为外设运行)或修改后的 DS (作为中央+外设运行)?
    3. 在调试模式下运行代码时、器件是否也会挂起? 您能分享一下代码悬挂在哪里吗? 器件挂起时已暂停调试会话的屏幕截图有助于共享。
    4. 如何配置 UART 驱动程序(参数)?

    BR、

    David。

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

    以下是详细信息-  

    1. simplelink_lowpower_f3_sdk_8_40_00_61
    2.修改后的 DS 作为中央+外设运行

    3.我尚未将其选中为调试模式。 如果在 UART 级别或数据处理中需要进行任何修改、请提供建议。  


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

    您好、Aman、

    我建议进入调试模式并查看程序崩溃的位置、以便我们能够获得有关可能发生的情况的更多信息。 从你分享的东西,我还不知道会发生什么。 然而、您提到您需要9600波特率、这是向 PC 传输数据还是向另一个主机器件传输数据所需的波特率? 您能给我展示一下您在何处修改波特率吗?

    BR、

    David。