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: Simple Central With Multiples Scans

Part Number: CC2640R2F

Tool/software: Code Composer Studio

Hello,

I'm having trouble reconnecting simple_central and simple_peripheral.

The idea is that simple_central constantly searches for peripherals. Being able to connect with up to 8 devices.

The problem that occurs is that when starting simple_central it connects to the two available devices. If I turn-off and turn-on one of the peripherals, simple_central can no longer connect to the device again.

The timeout is configured in 2s at simple_central.

The simple_peripheral can be detected by Btool after being switched on again.

Do I need a command to clean up lost connections?

       switch (*fsm_control)
        {
          case BLE_INIT:
              if(GL_Ble_Init_Done == 1){
                  *fsm_control = BLE_IDLE;
              }
             break;

          case BLE_IDLE:
              if(numConn<2){
                  *fsm_control = BLE_SCAN;
              }
            break;

          case BLE_SCAN:
              SimpleCentral_enqueueMsg(SC_EVT_SCAN_ENABLED, SUCCESS, NULL);
              *fsm_control = BLE_WAIT_SCAN;
              *fsm_timer = GL_Count_50ms + 7;
            break;

          case BLE_WAIT_SCAN:
                if(numScanRes>0){
                    *fsm_conn_control = numScanRes;
                    *fsm_control = BLE_CONNECT;
                }else{
                    *fsm_control = BLE_IDLE;
                }
            break;

          case BLE_CONNECT:
              for(uint8_t i=0; i<*fsm_conn_control; i++)
                  SimpleCentral_enqueueMsg(SC_EVT_CONNECT_ENABLED, i, NULL);
              *fsm_control = BLE_WAIT_CONNECT;
              *fsm_timer = GL_Count_50ms + 5;
            break;

          case BLE_WAIT_CONNECT:
               *fsm_control = BLE_IDLE;

            break;

          default:
              *fsm_control = BLE_INIT;
            break;

simplelink_cc2640r2_sdk_4_20_00_04

  • Hi Dhiego,

    I have assigned an expert to help you with your issue. Have you taken a look at the API GAPRole_TerminateConnection() to see if this a suitable solution?

    Best Regards,

    Jenny

  • Hello Jenny,

    I added more commands in the FSM to wait for the answer of each command and I was able to solve the reconnection issue.

    However, now simple_central is crashing. During debugging the following message is displayed.

    I configured simple_central to connect a maximum of 2 peripherals. When the 2 peripherals are found, the scan is disabled. If only 1 peripheral is connected, the scan keeps searching.

    If simple_central connects to both devices, the software works perfectly. But if it connects to just 1 peripheral and continues scanning for more devices, simple_central will crash after a few seconds.

    If the o define SC_TASK_STACK_SIZE is increased from 1024 to 2048, simple_central takes longer to crash.

    It seems that the consecutive scans are filling the memory.

  • Dhiego,

    It is hard to pinpoint the root cause with the information provided. However, from what you say, it feels like you have a memory leak.

    Is the state machine that you are showing implemented in the central? what is its purpose?

    thanks,

    Luis

  • Hello Luis,

    Yes, the state machine was implemented in simple_central.

    The product has no keys, display or wired communication. The search for peripherals must be carried out constantly. The scan is only changed when the product enters the configuration mode (SCAN_FLT_POLICY_ALL) where the peripherals are recorded. In normal mode the search is for the whitelist (SCAN_FLT_POLICY_WL).

    The current code is based on the simple_central example. I removed the simple_central_menu and added the state machine to the main loop.

    No malloc was added. The software only crashes if the scan command is used constantly.

    I also added the code below so that the software is not blocked waiting for events.

        if(Event_getPostedEvents(syncEvent)){
            events = Event_pend(syncEvent, Event_Id_NONE, SC_ALL_EVENTS, ICALL_TIMEOUT_FOREVER);
        }

    Perhaps a "free" was lost during the removal of the example menus. I will try to create another project from scratch to check if the same occurs.

  • Hello Luis,

    The problem was solved by recreating the entire project from scratch.

    I also used simplelink_cc2640r2_sdk_4_30_00_08.

    Thank you for your attention.