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.

LP-EM-CC2340R53: [BLE 6.0 CS DKC]Transmitting External Data to BLE Stack via BLE Message Queue

Part Number: LP-EM-CC2340R53

Tool/software:

Hi, Ti

*SDK version: 9.11.00.18 ,example: key_node

We need to transmit keypress events over Bluetooth. To achieve this, I have modified the key interrupt callback function to forward the key data to the BLE stack through the BLE message queue.

void BLE_button_event(uint32_t event, GapAdv_data_t *pBuf, uint32_t arg)
{
    BLEAppUtil_AdvEventData_t *pData = BLEAppUtil_malloc(sizeof(BLEAppUtil_AdvEventData_t));

    if (pData != NULL)
    {
        pData->event = event;
        pData->pBuf = pBuf;
        pData->arg = &arg;

        // Enqueue the event
        if (BLEAppUtil_enqueueMsg(BLEAPPUTIL_EVT_ADV_CB_EVENT, pData) != SUCCESS)
        {
            if (pBuf != NULL)
            {
                BLEAppUtil_free(pBuf);
            }
            BLEAppUtil_free(pData);
        }
    }
    else
    {
        if (pBuf != NULL)
        {
            BLEAppUtil_free(pBuf);
        }
    }
}

void App_ButtonCallBack(uint32_t events, uint32_t button_id)  /*IN: Events from keyboard module  */
{
    BLE_button_event(events, NULL, button_id);
}

/*
 *  ======== handleButtonCallback ========
 */
void handleButtonCallback(Button_Handle handle, Button_EventMask events)
{
    if (Button_EV_CLICKED == (events & Button_EV_CLICKED))
    {
        if(handle == buttonHandle[CONFIG_BUTTON_0])
        {
            button_num = 0x00;
            App_ButtonCallBack(BLEAPPUTIL_BUTTON_CLICK, button_num);
        }
        else if(handle == buttonHandle[CONFIG_BUTTON_1])
        {
            button_num = 0x01;
            App_ButtonCallBack(BLEAPPUTIL_BUTTON_CLICK, button_num);
        }
        else
        {}
    }
}

I receive and print the keypress data in Peripheral_AdvEventHandler, but find that the received advMsg->arg sometimes doesn't match the expected value, appearing to have changed during the process.

Is my approach of transmitting keypress data to the Bluetooth stack compliant with specifications? What could be causing this abnormal data variation?

/*********************************************************************
 * @fn      Peripheral_AdvEventHandler
 *
 * @brief   The purpose of this function is to handle peripheral state
 *          events that rise from the GAP and were registered
 *          in @ref BLEAppUtil_registerEventHandler
 *
 * @param   event - message event.
 * @param   pMsgData - pointer to message data.
 *
 * @return  none
 */
static void Peripheral_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
//  if (pMsgData != NULL)
//  {
//    // Send the event to the upper layer
//    Peripheral_extEvtHandler(BLEAPPUTIL_GAP_ADV_TYPE, event, pMsgData);
//  }
    BLEAppUtil_AdvEventData_t *scanMsg = (BLEAppUtil_AdvEventData_t *)pMsgData;

    switch(event)
    {
        case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
        {
            PHSCA_ESELOG_PRINTF("Adv status: Started - handle: %d", ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);

            break;
        }

        case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
        {
            PHSCA_ESELOG_PRINTF("Adv status: Ended - handle: %d", ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);

            if(linkDB_NumActive() < linkDB_NumConns())
            {
                Peripheral_advStart(pMsgData);
            }

            break;
        }

        case BLEAPPUTIL_BUTTON_CLICK:
        {
            PHSCA_ESELOG_PRINTF("scanMsg->arg[0x%2x]\r\n", (*(scanMsg->arg))&0xFF);

            break;
        }

        default:
        {
            break;
        }
    }
}

Best regards!

Preston