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.

CC2650 Advertising on/off

Other Parts Discussed in Thread: CC2541, CC2650

I'm porting a CC2541 app to the CC2650 on the SimpleLink CC2650 development kit. It's been easy except for
the fact that I cannot turn off advertising once it begins. I call GAPRole_SetParameter
(GAPROLE_ADVERT_ENABLED, 1, &en) with en=0. I verify that GAP_EndDiscoverable(selfEntity) is being executed
in peripheral.c. But once on, advertising stays on. I tried the same by adding code to SimpleBLEPeripheral to
switch off advertising after 10 seconds. Same result. Advertising remains on. Is something else required?

I have noticed a behavior that may not be relevant. If I turn off advertising then connect to the device (because advertising is not really off), on disconnect advertising stops.

Thanks,

Don.

  • Hi,
    Have you based this on SimpleBLEPeripheral? If you set the following variable to FALSE,
    uint8_t initialAdvertEnable = TRUE;

    in the beginning does it work?
  • Zahid Haq,

    If I make this change to SimpleBLEPeripheral:

    uint8_t initialAdvertEnable = FALSE;

    then there is no advertising. But then advertising starts five seconds later by adding the following code to SimpleBLEPeripheral:

    Clock_Struct TestClock;
    uint8_t mode=0;
    uint16_t tick=0;

    static void _clockHandler(UArg arg)
    {
    tick++;
    Util_startClock( &TestClock ); // restart the timer
    if( tick==5 )
    {
    mode=1;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, 1, &mode ); // Adv=on
    }
    else if( tick==10 )
    {
    mode=0;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, 1, &mode ); // Adv=off
    tick=0;
    }
    }

    void Test_Init(void)
    {
    Util_constructClock ( &TestClock, _clockHandler, 1000, 1000, 0, 0 );
    Util_startClock( &TestClock );
    }

    I put a call to TEST_Init() as the last line in SimpleBLEPeripheral_init(). I set breakpoints in peripheral.c at lines 297, 303, and 307. Line 297 (GAP_EndDiscoverable) gets executed repeatedly every 10 seconds as I would expect. Line 307 (gapRole_setEvent(START_ADVERTISING_EVT)) gets executed once. It never gets called again because it's not executed unless advertising is in fact off, which it isn't.

    The LCD also reflects this behavior. It shows "Initialized" for five seconds then "Advertising" thereafter.

    Thanks,
    Don.
  • Hello Don.  What you are doing in your original post looks fine. I just tried this out and am seeing it successfully turn off advertising. I've attached a modified simpleBLEPeripheral.c file which will toggle advertising on and off in the periodic task function for reference.

    /cfs-file/__key/communityserver-discussions-components-files/538/simpleBLEPeripheral.c

  • Tim,

    Your code worked. It led me in the right direction. Apparently there are certain things that should not be done in a clock timeout routine. Now I just post a 'sem' request and let everything else happen from a task loop like SimpleBLEPeripheral_taskFxn.

    Thanks for your help.
    Don.

  • Hi Tim,
    What will be the maximum limit of the clockDuration in util_constructclock function. That is what will be the maximum time we can set by using this function.

    Thanks
    Siva Krishna.
  • The API is defined in Section 3.4 of the User's Guide and the code is in util.c. The duration parameter is uint32_t so with the default tick period of 10 us, the max duration is ((2^32)-1) * 10 us
  • i understood your code, but i dont want to execute periodically 5sec on and 10sec off, what i want is, device has to scan if there is no connection with in 10 seconds then the device should automatically get advertisement off, and later i will turn off the power. if there is any connection then sensor has to do its normal work.
  • When I run this it doesn't toggle for me?
    Conditions of interest seem to be:

    uint8_t initialAdvertEnable = TRUE; and

    static void SimpleBLEPeripheral_performPeriodicTask(void)
    {
    //turn off advertising
    en ^= 1;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, 1, &en);
    }

    What I see is that the device will just turn off the advertising and will not toggle it.....


    Also another question is do you happen to know if this works while connected or not?

    I am trying to solve my issues here in this post and your example got me rather far but not quite all the way yet as I cannot get the system to properly toggle advertising.
    e2e.ti.com/.../499008

  • Am I the only one that is not getting this to work with the new stack that is out?