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: Unable to set the advertising interval for the Broadcaster.

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG, ENERGYTRACE

Hi Expert,
I have a project that uses both Central and Broadcaster roles. I want to set the advertising interval to 3000ms and use a 100-byte extended packet.
I tried setting the interval to 3000ms, but it’s not working as expected. Could you please provide some guidance on this?

CCS Version: 20.4.0.13__1.10.0

image.png

Please find my code and SysConfig configuration below.

*****************************************************************************/

#if defined( HOST_CONFIG ) && ( HOST_CONFIG & ( BROADCASTER_CFG ) )

//*****************************************************************************
//! Includes
//*****************************************************************************
#include "ti_ble_config.h"
#include "ti/ble/app_util/framework/bleapputil_api.h"
#include "ti/ble/app_util/menu/menu_module.h"
#include <app_main.h>

//*****************************************************************************
//! Prototypes
//*****************************************************************************
void Broadcaster_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData);

//*****************************************************************************
//! Globals
//*****************************************************************************
static uint8_t test_ccnt = 0;

BLEAppUtil_EventHandler_t broadcasterAdvHandler =
{
    .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
    .pEventHandler  = Broadcaster_AdvEventHandler,
    .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                      BLEAPPUTIL_ADV_END | 
                      BLEAPPUTIL_ADV_END_AFTER_DISABLE
};

//! Store handle needed for each advertise set
uint8 broadcasterAdvHandle_1;

const BLEAppUtil_AdvInit_t broadcasterInitAdvSet1 =
{
    /* Advertise data and length */
    .advDataLen        = 0,//sizeof(advData1),
    .advData           = NULL,//advData1,

    /* Scan respond data and length */
    // .scanRespDataLen   = 0,
    // .scanRespData      = NULL,
    .scanRespDataLen   = sizeof(scanResData1),//0,
    .scanRespData      = scanResData1,//NULL,


    .advParam        = &advParams1
};

const BLEAppUtil_AdvStart_t broadcasterStartAdvSet1 =
{
  /* Use the maximum possible value. This is the spec-defined maximum for */
  /* directed advertising and infinite advertising for all other types */
  .enableOptions         = GAP_ADV_ENABLE_OPTIONS_USE_MAX,
  .durationOrMaxEvents   = 0
};

//*****************************************************************************
//! Functions
//*****************************************************************************

/*********************************************************************
 * @fn      Broadcaster_AdvEventHandler
 *
 * @brief   The purpose of this function is to handle advertise events
 *          that rise from the GAP and were registered in
 *          @ref BLEAppUtil_RegisterGAPEvent
 *
 * @param   event - message event.
 * @param   pMsgData - pointer to message data.
 *
 * @return  none
 */
void Broadcaster_AdvEventHandler(uint32 event, BLEAppUtil_msgHdr_t *pMsgData)
{
    switch(event)
    {
        case BLEAPPUTIL_ADV_START_AFTER_ENABLE:
        {
            MenuModule_printf(APP_MENU_ADV_EVENT+5, 0, "Adv status: Started - handle: "
                              MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                              ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);

            break;
        }

        case BLEAPPUTIL_ADV_END_AFTER_DISABLE:
        {
            MenuModule_printf(APP_MENU_ADV_EVENT, 0, "Adv status: Ended - handle: "
                              MENU_MODULE_COLOR_YELLOW "%d" MENU_MODULE_COLOR_RESET,
                              ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle);
            break;
        }
        case BLEAPPUTIL_ADV_END:
                            MenuModule_printf(APP_MENU_ADV_EVENT+5, 0, "Adv EEEEEEEs: Started - handle: "
                                  MENU_MODULE_COLOR_YELLOW "%d Count = %d" MENU_MODULE_COLOR_RESET,
                                  ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle, test_ccnt++);

                /** New Code **/
            BLEAppUtil_AdvEventData_t * pkt = (BLEAppUtil_AdvEventData_t *)pMsgData;

            if (pkt->pBuf->advHandle == broadcasterAdvHandle_1) 
            {
                bStatus_t status = FAILURE;

                status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE); 

                if (status != SUCCESS)
                    for(;;); // Loop

                uint8_t ADV_DATA2_LEN = (111 - 7);
                //uint8_t *advData2 = ICall_malloc(ADV_DATA2_LEN);
                uint8_t advData2[104] = {0};
                
                advData2[0] = (ADV_DATA2_LEN - 1);
                advData2[1] = GAP_ADTYPE_MANUFACTURER_SPECIFIC;

                //Company Identifier
                advData2[2] = 0x0d;
                advData2[3] = 0x00;

                for(uint8_t i = 0; i<100; i++)
                     advData2[4 + i] = (i + 1);



                // broadcasterAdvHandler.eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                //                                        BLEAPPUTIL_ADV_END | // <--- new dynamic advertising.  
                //                                        BLEAPPUTIL_ADV_END_AFTER_DISABLE;


                status = GapAdv_loadByHandle(broadcasterAdvHandle_1, // broadcasterAdvHandle_1 ,broadcasterAdvHandler.pEventHandler
                                            GAP_ADV_DATA_TYPE_SCAN_RSP, //GAP_ADV_DATA_TYPE_SCAN_RSP , GAP_ADV_DATA_TYPE_ADV ,BLEAPPUTIL_GAP_ADV_TYPE,
                                            ADV_DATA2_LEN,
                                            advData2);

                 if (status != SUCCESS)
                     for(;;);
                /** End New Code **/

             }
                    break;
        default:
        {
            break;
        }
    }
}

image.png

image.png

image.png

image.png

image.png

 

  • Hi,

    Thank you for reaching out. The settings you have shared look correct. Can you share what behavior you are seeing? Are you getting any errors? Is the code hanging somewhere?

    Best Regards,

    Jan

  • Hi Jan, if the broadcaster is set to advertise every 3 seconds, shouldn't BLEAPPUTIL_ADV_END be triggered once every 3 seconds as well? My UART logs show it's firing much faster than that, which is confusing. Is my understanding of this event correct?





    Regards,

    Anthony

  • Hi,

    Thank you for reaching out. The EnergyTrace measurement you are showing is showing a much faster advertising interval that 3 seconds. Seems you are using an advertising interval of 20ms. One advertising event (when using all 3 channels) shows up as 3 peaks in quick succession (if no scan responses are sent). Can you share how you are setting the advertising interval?

    Best Regards,

    Jan

  • Hi Jan,

    I only adjusted the Primary PHY Interval Minimum (ms) and Primary PHY Interval Maximum (ms) to 3000 within the Advertisement Parameters of syscfg, along with some minor corrections to const BLEAppUtil_AdvInit_t broadcasterInitAdvSet1. You can refer to the code in my original post; perhaps try loading my code into app_broadcaster.c to see if it works.

    BLEAppUtil_EventHandler_t broadcasterAdvHandler =
    {
        .handlerType    = BLEAPPUTIL_GAP_ADV_TYPE,
        .pEventHandler  = Broadcaster_AdvEventHandler,
        .eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                          BLEAPPUTIL_ADV_END | 
                          BLEAPPUTIL_ADV_END_AFTER_DISABLE
    };


    const BLEAppUtil_AdvInit_t broadcasterInitAdvSet1 =
    {
        /* Advertise data and length */
        .advDataLen        = 0,//sizeof(advData1),
        .advData           = NULL,//advData1,
    
        /* Scan respond data and length */
        // .scanRespDataLen   = 0,
        // .scanRespData      = NULL,
        .scanRespDataLen   = sizeof(scanResData1),//0,
        .scanRespData      = scanResData1,//NULL,
    
    
        .advParam        = &advParams1
    };


            case BLEAPPUTIL_ADV_END:
                                MenuModule_printf(APP_MENU_ADV_EVENT+5, 0, "Adv EEEEEEEs: Started - handle: "
                                      MENU_MODULE_COLOR_YELLOW "%d Count = %d" MENU_MODULE_COLOR_RESET,
                                      ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle, test_ccnt++);
    
                    /** New Code **/
                BLEAppUtil_AdvEventData_t * pkt = (BLEAppUtil_AdvEventData_t *)pMsgData;
    
                if (pkt->pBuf->advHandle == broadcasterAdvHandle_1) 
                {
                    bStatus_t status = FAILURE;
    
                    status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE); 
    
                    if (status != SUCCESS)
                        for(;;); // Loop
    
                    uint8_t ADV_DATA2_LEN = (111 - 7);
                    //uint8_t *advData2 = ICall_malloc(ADV_DATA2_LEN);
                    uint8_t advData2[104] = {0};
                    
                    advData2[0] = (ADV_DATA2_LEN - 1);
                    advData2[1] = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
    
                    //Company Identifier
                    advData2[2] = 0x0d;
                    advData2[3] = 0x00;
    
                    for(uint8_t i = 0; i<100; i++)
                         advData2[4 + i] = (i + 1);
    
    
    
                    // broadcasterAdvHandler.eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                    //                                        BLEAPPUTIL_ADV_END | // <--- new dynamic advertising.  
                    //                                        BLEAPPUTIL_ADV_END_AFTER_DISABLE;
    
    
                    status = GapAdv_loadByHandle(broadcasterAdvHandle_1, // broadcasterAdvHandle_1 ,broadcasterAdvHandler.pEventHandler
                                                GAP_ADV_DATA_TYPE_SCAN_RSP, //GAP_ADV_DATA_TYPE_SCAN_RSP , GAP_ADV_DATA_TYPE_ADV ,BLEAPPUTIL_GAP_ADV_TYPE,
                                                ADV_DATA2_LEN,
                                                advData2);
    
                     if (status != SUCCESS)
                         for(;;);
                    /** End New Code **/
    
                 }
                        break;

    Regards,

    Anthony

  • Hi Anthony,

    Got it. The code you are using looks good, but when using the GapAdv APIs, you must set the advertising interval using the GapAdv_setParam() API. Please try adding that to your code with your desired interval.

    Best Regards,

    Jan

  • Hi Jan,

    Even after implementing GapAdv_setParam(), the outcome hasn't changed. If the SysConfig specifies a 3000ms interval, the system should follow those initial parameters by default without requiring an extra GapAdv_setParam() call to 'set' what is already defined. Could this behavior be specific to Extended Advertising?

    Regards,

    Anthony

  • Hi Jan,
    "I've found that removing the code within BLEAPPUTIL_ADV_END restores the correct advertising interval. However, this isn't the desired outcome because I need to dynamically adjust data within the extended advertising. Once I re-include that code, the advertising interval deviates again. Do you have any other suggestions?

            case BLEAPPUTIL_ADV_END:
                                MenuModule_printf(APP_MENU_ADV_EVENT+5, 0, "Adv EEEEEEEs: Started - handle: "
                                      MENU_MODULE_COLOR_YELLOW "%d Count = %d" MENU_MODULE_COLOR_RESET,
                                      ((BLEAppUtil_AdvEventData_t *)pMsgData)->pBuf->advHandle, test_ccnt++);
    
                    /** New Code **/
                BLEAppUtil_AdvEventData_t * pkt = (BLEAppUtil_AdvEventData_t *)pMsgData;
    
                if (pkt->pBuf->advHandle == broadcasterAdvHandle_1) 
                {
                    bStatus_t status = FAILURE;
    
                    status = GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE); 
    
                    if (status != SUCCESS)
                        for(;;); // Loop
    
                    uint8_t ADV_DATA2_LEN = (111 - 7);
                    //uint8_t *advData2 = ICall_malloc(ADV_DATA2_LEN);
                    uint8_t advData2[104] = {0};
                    
                    advData2[0] = (ADV_DATA2_LEN - 1);
                    advData2[1] = GAP_ADTYPE_MANUFACTURER_SPECIFIC;
    
                    //Company Identifier
                    advData2[2] = 0x0d;
                    advData2[3] = 0x00;
    
                    for(uint8_t i = 0; i<100; i++)
                         advData2[4 + i] = (i + 1);
    
    
    
                    // broadcasterAdvHandler.eventMask      = BLEAPPUTIL_ADV_START_AFTER_ENABLE |
                    //                                        BLEAPPUTIL_ADV_END | // <--- new dynamic advertising.  
                    //                                        BLEAPPUTIL_ADV_END_AFTER_DISABLE;
    
    
                    status = GapAdv_loadByHandle(broadcasterAdvHandle_1, // broadcasterAdvHandle_1 ,broadcasterAdvHandler.pEventHandler
                                                GAP_ADV_DATA_TYPE_SCAN_RSP, //GAP_ADV_DATA_TYPE_SCAN_RSP , GAP_ADV_DATA_TYPE_ADV ,BLEAPPUTIL_GAP_ADV_TYPE,
                                                ADV_DATA2_LEN,
                                                advData2);
    
                     if (status != SUCCESS)
                         for(;;);
                    /** End New Code **/
                    
                                     uint32_t advInterval = 0;
    
    
                     advInterval = 4800;
                     GapAdv_setParam(broadcasterAdvHandle_1,
                                     GAP_ADV_PARAM_PRIMARY_INTERVAL_MIN,
                                     &advInterval);
    
                     GapAdv_setParam(broadcasterAdvHandle_1,
                                     GAP_ADV_PARAM_PRIMARY_INTERVAL_MAX,
                                     &advInterval);
    
                 }
                        break;


    Regards,

    Anthony

  • Hi Anthony,

    Glad to hear you were able to find the root cause. It is not recommend to change advertising parameters while the advertisements are enabled. Can you try disabling the advertisements, changing the speed, and the re-enabling them? 

    Best Regards,

    Jan

  • Hi Jan,

    I tried disabling the ads, adjusting the playback speed, and then re-enabling them, but the result remained the same. Later, I discovered that by commenting out GapAdv_prepareLoadByHandle(broadcasterAdvHandle_1, GAP_ADV_FREE_OPTION_DONT_FREE);, the advertising interval returned to normal. It now correctly follows the Primary PHY Interval Minimum/Maximum settings configured in SysConfig.

    Regards,

    Anthony

  • Hi,

    Glad to hear you were able to find a fix for this. Its likely that the global variable updated by sysconfig may be ignored when using that API. Thank you for sharing this with the community!

    Best Regards,

    Jan