Tuesday, December 17, 2019

How to create a periodic event to toggle BLE Advertising in CC26xx simple_peripheral example

The following steps show you how to create a periodic event to toggle BLE Advertising every 10 seconds in CC26xx simple_peripheral example.

In simple_peripheral.c, add the following codes:

1. Add "#define ADV_PERIODIC_EVT Event_Id_01" for new periodic event.

2. Add "#define ADV_PERIODIC_EVT_PERIOD 10000" to define the period as 10 seconds.

3. Add ADV_PERIODIC_EVT to Bitwise OR of all events to pend on.

    #define SBP_ALL_EVENTS       (SBP_ICALL_EVT        | \
                                                         SBP_QUEUE_EVT        | \
                                                         ADV_PERIODIC_EVT     | \
                                                         SBP_PERIODIC_EVT)

4. Add "advertEnabledPeriod = TRUE;" as a global variable for toggling BLE advertising.

5. Add "static Clock_Struct periodicClockAdv;" for periodic clock.

6. In SimplePeripheral_init(), add the following lines to start periodic event for toggling BLE advertising.

    Util_constructClock(&periodicClockAdv, SimplePeripheral_clockHandler,
                      ADV_PERIODIC_EVT_PERIOD, 0, false, ADV_PERIODIC_EVT);
    Util_startClock(&periodicClockAdv);



7.  Add the following codes in SimplePeripheral_taskFxn() to toggle BLE advertising in ADV_PERIODIC_EVT event which is triggered every 10 seconds.

      if (events & ADV_PERIODIC_EVT)
      {
        Util_startClock(&periodicClockAdv);
        if(advertEnabledPeriod==TRUE){
            advertEnabledPeriod=FALSE;
        } else {
            advertEnabledPeriod=TRUE;
        }
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                                 &advertEnabledPeriod);

      }


8. After building and download hex into your CC26xx device, you can use SimpleLink Starter APP to scan and check if BLE advertising is toggled every 10 seconds.

1 comment:

  1. Hi there,

    If you do not mind, would that be possible you could help to send me the complete codes here?
    Or send to my email jack_apple123456@hotmail.com

    Many thanks

    ReplyDelete