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.

CCS/CC2640R2F: how to perform advertising and scanning periodically using CC2640r2f?

Part Number: CC2640R2F

Tool/software: Code Composer Studio

I have to use the scanning and advertising both. So let's say on power up board is advertising and after 1 min board need to scan the available peripheral devices. And this will happen continuously means device will advertise and then scan periodically. So any can  suggest me how should I do this.  In what part of multi role I need to change. Thank you.

  • Pradeep,

    You could either utilize or create something similar to the MR_PERIODIC_EVT in multi_role.c. Use a clock that you define the period to, and whenever you receive an event, do whatever logic you wish to do to switch advertising and scanning off/on. Remember you can't do both advertising and scanning at the same physical time.

    I would examine how MR_PERIODIC_EVT is used and essentially use this.
  • So now I am able to perform scanning and advertising without using any Button. I did this by using GAPRole_cancelDiscovery function in GAP_DEVICE_DISCOVERY event after scanning all the devices. I studied in BLE stack guide that We need not not to start the advertising as this will automatically start automatically in LINK_TERMINATE event if device is not scanning and advertising. So this is working fine for me. Now I am not getting how to send multidimensional array over BLE. the array is of size around 10x10x10 like DATA[10][10][10] and contain large data more than 1000 bytes. till now I just send on 1-dimension array. But how can I send this.
  • But now I am facing same issue as poweIN mention in e2e.ti.com/.../684299
    . I set MAX_NUM_BLE_CONNS=3. Now when I connect device with app and disconnect it then no issue, second time when I connect device with app and disconnect it no problem, its advertising. in third time when I connect the device with app and disconnect it, now device stop advertising and all the processing also stop. no advertising no scanning while I am using the same phone. So using a the same device when I connect and disconnect it for more than three times it stop advertising and scanning. Means everything stopped. SO kindly look into the issue thank You.
  • I am waiting for reply.
  • Pradeep,

    When I set my MAX_NUM_BLE_CONNS=3 in the pre-defined settings, it's only limiting me/you to the number of active connections. You are right that if you connect 3 devices, then disconnect one or all of them, that the device no longer advertises. But you can use the buttons on the LaunchPad to navigate through the menu as i mentioned above to trigger advertising. If you wish to get this running on a board without buttons, find the portion of code in multi_role that turn off and on advertising based on the number of active connections you have.

    This is done in multi_role_processRoleEvent. In the case statement for GAP_LINK_ESTABLISHED_EVENT, there is some code that finds the number of active connections and if it equals or exceeds the maxNumBleConnections it turns off advertising (lines 1125 or so).

    To edit the program to advertise immediately after the number of active connections drops below the maxNumBleConns variable, look at the case statement for GAP_LINK_TERMINATED_EVENT. In there, add some logic to check the number of active connections after receiving the GAP_LINK_TERMINATED_EVENT and turn advertising on by the following


    uint8_t adv = TRUE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &adv, NULL);
  • I am not connecting three devices, I am just connecting only single devices that is my phone with cc2640r2 and CC2640r2 stops advertising when I connect and disconnect the phone for more than 3 times. So it does not matter whether you are connecting 3 device at once or single for 3 times. It always keep counting no of connections whenever you connect or connect or disconnect. And this counting of no of connections does not come down, after disconnecting the device.
    So is there any way by which I can reset this linkDB_NumActive(); function once maxnumofconnection reached.

    I have already seen this portion of code in GAP_LINK_ESTABLISHED_EVENT

    if (linkDB_NumActive() >= maxNumBleConns)
    {
    uint8_t advertEnabled = FALSE;
    GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &advertEnabled, NULL);
    //Display_print0(dispHandle, MR_ROW_ADV, 0, "Can't adv: no links");
    }
    by the way I changed it to advertEnabled = TRUE; for testing purpose but this does not work. I also commented this portion of code for testing purpose. So I found that the device will stop advertising automatically once max no connection reached, and it has no effect whether we set advertEnable= TRUE or comment this portion.

    As you have mentioned above in GAP_LINK_TERMINATED_EVENT I added that portion of the code also but still it has no effect.

  • Pradeep,

    I'm sorry you are still having difficulties. I'll look further deeper into this tomorrow, however, when I tested this example in the SDK v1.50.00.58, I connected and disconnected upwards of five or six times using an iPhone. I will investigate this and follow up with you as soon as I know more. What device are you using by chance?

  • Thanks Evan Wakefield for such a great support, I am using moto g5 android phone. I am using BLE scanner app for connecting with the device.
  • Hi Evan, I got multi_role working. Its working standalone. But whenever i add my code of GPS, OLED and IMU, I get above mentioned issues. Previously i was working with simple_peripheral and in simple_peripheral i did not get these problems but why i am getting this issue, i need to figure it out.
  • So finally i got everything working. Now i can advertise and scan also and it is working perfectly but using SIMPLE_BLE_peripheral observer project not with Multi_role. Thank you so much Evan for support.