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:BLE Central 在调用 GATT_WriteCharValue () 时输入 Exception_handlerSpin ()

Guru**** 2419530 points
Other Parts Discussed in Thread: CC2340R5

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

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1536721/cc2340r5-ble-central-enter-exception_handlerspin-when-call-gatt_writecharvalue

器件型号:CC2340R5


工具/软件:

simplelink_lowpower_f3_SDK_8_40_00_61\examples\rtos\LP_EM_CC2340R5\ble5stack\basic_ble\

CC2340 作为 BLE 中心。 它连接外设、服务 和特征请求和响应工作、  

 当调用 GATT_WriteCharValue () 时、CC2340 中央设备在 exception_handlerSpin () 中进入循环。

使用 BLEAppUtil_invokeFunction。

但  在调用 GATT_WriteLongCharValue() 时它不会进入 exception_handlerSpin()。

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

    您好 Bryte、

    如何实现 GATT_Write () 函数? 您能否分享一个代码片段、说明如何调用该函数以及对应的上下文。

    我建议使用以下示例作为参考: https://github.com/TexasInstruments-Sandbox/ble_examples/tree/simplelink_low_power_f3_sdk-8.40/examples/rtos/LP_EM_CC2340R5/ble5stack/basic_ble_GATT_client

    此致、

    David。

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

    感谢您的答复! 我已经在 GitHub 上下载了示例,我分享了代码(请不要犹豫,让我展示更多的代码,它现在不是秘密的)  ,现在再次在 GitHub 上查看示例。

    TimerHandle_t hbtTimer = create_periodic_timer(5000, heartbeat_timerCB, (void *)1);
    
    void heartbeat_timerCB(TimerHandle_t xTimer)
    {
    static uint32 cnt = 0;
    Display_doPrintf(displayHandle, my_printLine, 0, "~ ");
    
    if (0 == is_connected) {
    cnt=0;
    return ;
    }
    
    cnt ++;
    if (1 == cnt) {
    BLEAppUtil_invokeFunction(tx_service_discovery, NULL); // works fine
    } else if (2 == cnt) {
    BLEAppUtil_invokeFunction(tx_service_discovery_by_uuid, NULL); // works fine
    } else if (7 == cnt) {
    BLEAppUtil_invokeFunction(tx_ble_ctrl_cmd, NULL); // hang if call GATT_WriteCharValue in it.
    }
    }
    
    
    void tx_ble_ctrl_cmd(char* pData)
    {
    attWriteReq_t writeReq;
    uint8_t command;
    
    BLEAppUtil_entityId_t entityid = BLEAppUtil_getSelfEntity();
    uint16_t connhd = Connection_getConnhandle(0);
    
    if (wr_handle[0]==0 && wr_handle[1]==0)
    return ;
    
    command = (command == CMD_TURN_ON ? CMD_TURN_OFF : CMD_TURN_ON);
    writeReq.handle = (wr_handle[1]<<8 | wr_handle[0]);
    writeReq.len = sizeof(command);
    writeReq.pValue = (uint8 *)&command;
    writeReq.sig = 0;
    writeReq.cmd = 0;
    
    Display_doPrintf(displayHandle, my_printLine++, 0, "tx_ble_ctrl_cmd_short connhd:%u.entity:%u. hd:0x%x.\n", connhd, entityid, writeReq.handle);
    if (65535 == connhd)
    return ;
    #if 1
    bStatus_t ret = GATT_WriteCharValue(connhd, &writeReq, entityid); // hang, 
    Display_doPrintf(displayHandle, my_printLine++, 0, "GATT_WriteCharValue : %u.\n", ret);
    #else
    bStatus_t ret = GATT_WriteLongCharValue(connhd, &writeReq, entityid); 
    Display_doPrintf(displayHandle, my_printLine++, 0, "GATT_WriteLongCharValue : %u.\n", ret);
    #endif
    }

    调用 GATT_WriteLongCharValue() 不会挂起、但会得到  

    reqopc:22、错误代码:9
    #define ATT_ERR_PREPARE_QUEUE_FULL 0x09 //!<有太多准备写入排队

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

    您好:

    谢谢。 您发送的数据的大小(命令)是多少? 此外、如何创建周期性计时器?

    BR、

    David。

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

    1、数据大小为 1 字节(uint8_t 命令;)。

    2.  

    TimerHandle_t create_periodic_timer (uint32_t period_ms、TimerCallbackFunction_t 回调、void *timer_id)

    TimerHandle_t xTimer;
    basetype_t xResult;

    xTimer = xTimerCreate(
    “UserTimer",“,</s>、
    PDMs_to_ticks (period_ms)、
    pdTRUE、
    timer_id、
    回调
    );

    if (xTimer !=NULL)

    xResult = xTimerStart (xTimer、0);
    if (xResult!= pdPASS)

    xTimerDelete(xTimer, 0);
    xTimer = NULL;
    }
    }

    返回 xTimer;
    }

    3.我比较了 https://github.com/TexasInstruments-Sandbox/ble_examples/tree/simplelink_low_power_f3_sdk-8.40/examples/rtos/LP_EM_CC2340R5/ble5stack/basic_ble_GATT_client/app 和 simplelink_lowpower_f3_SDK_8_40_00_61\examples\rtos\LP_EM_CC2340R5\ble5stack\basic_ble\app、只有 centralConnParams 和 centralScanInitParams 有差异、我尝试差分编码  8_40、它也会在 GATT_WriteCharValue 上挂起。

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

    忽略第 3 部分。 我曾说过 simplelink_lowpower_f3_SDK_9_11_00_18\examples\rtos\LP_EM_CC2340R5\basic_ble\app、而不是 simplelink_lowpower_f3_SDK_8_40_00_61  

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

    我已将 https://github.com/TexasInstruments-Sandbox/ble_examples/tree/simplelink_low_power_f3_sdk-8.40/examples/rtos/LP_EM_CC2340R5/ble5stack/basic_ble_GATT_client/app 与 simplelink_lowpower_f3_SDK_9_11_00_18\examples\rtos\LP_EM_CC2340R5\ble\basic_ble\app 进行比较。  

    也只有 centralConnParams 和 centralScanInitParams 中有 diff、忽略其他 diff 显然与问题没有关系。

    我尝试合并差分和测试、相同的问题。

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

    GATT_ReadCharValue() 在同一流程中工作正常。

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

    当 在 app_connection.c GATT_eventhandler () 中调用 GATT_WriteCharValue () 时、它不会挂起、但外设接收到格式错误的数据包、属性写入不起作用、而从中央器件发现服务并通知外设工作正常。

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

    您好 Bryte、

    我现在将尝试使用最新的 SDK 重现 GATT_WriteCharValue 并返回报告。 如果您现在有任何更新、请告诉我。

    BR、

    David。

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

    它现在有效,使用 gatt_bm_alloc () 对内存区域进行 malloc 以 writeReq.pValue。