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.

LAUNCHXL-CC2640R2: BLE5 Simple Peripheral - How to turn advertising on/off outside of simple peripheral task

Part Number: LAUNCHXL-CC2640R2

BLE5 Simple Peripheral example

SDK 4.20.00.04

I have a custom task that is to turn on/off advertising based on the commands it receives. I make a call to a function in simple peripheral that invokes GapAdv_enable/disable. It stops/starts the advertising once and then the code goes into ICall_abort. What is the proper way to start/stop advertising in a different task than the simple peripheral?

  • You can use the following code to enable advertising

    uint8_t AdvertEnable = TRUE;
    
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&AdvertEnable);

    and use the following code to disable it.

    uint8_t AdvertEnable = FALSE;
    
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),&AdvertEnable);

  • Hi Andrew,

    You may want to have your application post an Application event to simpleperipheral. This will allow your Simple_Peripheral task to pick up the event that you post and know to turn advertising on/off within the context of that the correct thread. To figure out how to do this, I would recommend referencing the the SimplePeripheral_processAppMsg function, and looking at the events that are there out-of-the-box. You will then need to make a function in your application that posts the event, and a function in Simple_peripheralc that processes this  event and toggles advertising using the function calls that Yikai posted.

    Best Regards,
    Alec