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.

CC2541: Disabling scan while connection

Part Number: CC2541
Other Parts Discussed in Thread: CC2540

Hello,

In my code, the device is starting scan before a connection. Thus in a high BLE traffic area, this is causing complication in connection. So now, what I want to do, is disable the scanning during this connection period and enable back when it is connected? Is there any indication from stack to application when connection is started and completed? S  Can I use GAPROLE_STARTED and GAPROLE_CONNECTED for this?

Thanks a lot .

Best,

  • Hi,

    Thank you for reaching out.

    Your approach seems correct to me. However, assuming you are on the central side, I think you should rather consider the events GAP_DEVICE_DISCOVERY_EVENT and GAP_LINK_ESTABLISHED_EVENT.

    For additional details, you may want to consult https://www.ti.com/lit/swru271

    Best regards,

  • Hi Clement,

    I am handling the role of Peipheral Observer ...I scan the sensors and send the packets to connected phone through an app. SO while getting connected to the phone, I want to disable the scanning of sensors.

    Best,

    Varun

  • Hi Varun,

    I did not get you were actually in Peripheral Observer mode.

    In that case, I guess the event you need is GAPROLE_CONNECTED. You can still refer to https://www.ti.com/lit/swru271 for additional details.

    With that being - if it was your question - there is no event raised by the stack on the peripheral side signaling the beginning of the connection establishment process. Only the event signaling the connection established is raised.

    Best regards,

  • Hi Clement,

    Thank you for you reply.

    If the beginning of connection establishment process is not known , we will not be able to disable the scanning during the connection window period, right? Because I don't want to disable the scanning till a connection is formed. 

    Best,

    Varun

  • Hi Clement,

    Below, I am attaching the configuration of GAP role Parameters in my code

    I am wondering tuning these parameters may help solve the issue?

    Between, do we get any indication on peripheral side when advertisements are turned off during the GAPROLE_ADVERT_OFF_TIME? (so that I could start scanning during this time)

    Best,

    Varun

  • Hi Varun,

    For other requests, I will kindly ask you to use the "insert code" function.

    You may want to modify the scan window for the discovery procedure (limited or general) you are using. This can be done using  TGAP_GEN_DISC_SCAN_WIND or TGAP_LIM_DISC_SCAN_WIND.

    I am not sure we really understand each other:

    - there is an event raised (GAP_LINK_ESTABLISHED_EVENT) when the connection is established

    - there is not an event raised when the device receives the connection request

    - there is an event raised when the advertising starts (GAP_MAKE_DISCOVERABLE_DONE_EVENT) and when the advertising ends (GAP_END_DISCOVERABLE_DONE_EVENT)

    All this information can be found in https://www.ti.com/lit/swru271

    Best regards,

  • Hi Clement,

    yes, I think we are on the same page. Thanks for your reply.. Inorder to not overlap the radio, I want to disable the scanning while connection is formed. But right now, I can only disable the scanning till a connection is formed and there is no problem with connection. But the problem now is the scanning starts only after a connection is established. But we want the scanning happening in the background. I want to do like the below figure (disable during formation of connection which is indicated in red)  

    So I use the below events to cancel the scan when the device is advertising. and starts when it is not.   But unfortunately,  I am having connection problem again.

    case GAP_MAKE_DISCOVERABLE_DONE_EVENT:
        case GAP_END_DISCOVERABLE_DONE_EVENT:
          {
            gapMakeDiscoverableRspEvent_t *pPkt = (gapMakeDiscoverableRspEvent_t *)pMsg;
    
            if ( pPkt->hdr.status == SUCCESS )
            {
              if ( pMsg->opcode == GAP_MAKE_DISCOVERABLE_DONE_EVENT )
              {
                gapRole_state = GAPROLE_ADVERTISING;
                GAPObserverRole_CancelDiscovery();
              }
              else // GAP_END_DISCOVERABLE_DONE_EVENT
              {
    
                if ( gapRole_AdvertOffTime != 0 )
                {
                  if ( ( gapRole_AdvEnabled ) )
                  {
                    GAPObserverRole_StartDiscovery( DEFAULT_DISCOVERY_MODE,DEFAULT_DISCOVERY_ACTIVE_SCAN,DEFAULT_DISCOVERY_WHITE_LIST );
                    VOID osal_start_timerEx( gapRole_TaskID, START_ADVERTISING_EVT, gapRole_AdvertOffTime );
                  }
                }
                else
                {
                  // Since gapRole_AdvertOffTime is set to 0, the device should not
                  // automatically become discoverable again after a period of time.
                  // Set enabler to FALSE; device will become discoverable again when
                  // this value gets set to TRUE
                  gapRole_AdvEnabled = FALSE;
                }
    
                // In the Advertising Off period
                gapRole_state = GAPROLE_WAITING;
    
              }
            }
            else
            {
              gapRole_state = GAPROLE_ERROR;
            }
            notify = TRUE;
          }
          break;

      uint16 scanduration = 1000U; 
      uint16 advertOffTime = 5000U;
      uint16 advertisingduration = 5000;
      uint8 enable_update_request = FALSE;//TRUE;
      uint16 desired_min_interval = 20U;
      uint16 desired_max_interval = 20U;
      uint16 desired_slave_latency = 0U;
      uint16 desired_conn_timeout = 1000U;
      uint16 rssi_read_rate = 500U;
      uint8 initial_advertising_enable = TRUE;
    
      // Set the GAP Role Parameters
      GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
      GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &advertOffTime );
      GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, scanResponseLength, scanRspData );
      GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
      GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request );
      GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
      GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
      GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency );
      GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout );
      GAPRole_SetParameter( GAPROLE_RSSI_READ_RATE, sizeof( uint16 ), &rssi_read_rate );
      //GAPRole_SetParameter( TGAP_LIM_DISC_SCAN, sizeof( uint16 ), &scanduration );
      //GAPRole_SetParameter( TGAP_GEN_DISC_ADV_MIN, sizeof( uint16 ), &advertisingduration );
      
    
      // Set the GAP Characteristics
      GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
    
      GAP_SetParamValue( TGAP_GEN_DISC_ADV_MIN, advertisingduration );
      // Set up the advertising interval
      static const uint16 advInt = 300U; //500 before
      GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt );
      GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt );
      GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt );
      GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt );    
    
      // Initialise the observer
      {
        uint8 scanRes = 60;
        GAPRole_SetParameter ( GAPOBSERVERROLE_MAX_SCAN_RES, sizeof( uint8 ), &scanRes );
      }
      // Setuo Scanning interval 
      GAP_SetParamValue( TGAP_LIM_DISC_SCAN, scanduration );
      GAP_SetParamValue( TGAP_LIM_DISC_SCAN_INT, 160  ); //Interval between the start of two consecutive scan windows
      GAP_SetParamValue( TGAP_LIM_DISC_SCAN_WIND, 128 ); //	The duration in which the Link Layer scans on one channel

  • Hi,

    I am afraid there is no way to detect the connection req reception on CC2540 device.

    Best regards,