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 connecting and disconnecting continously



Hi All,

In my application i am trying to turn off the advertisement and after 5 seconds i am trying to turn it on.But for the first connection after loading the code it is stable. But when i try to send an immediate alert code to disconnect it starts connecting and disconnecting continously.Here is my code snippet

if(ADVERT_OFF_PERIOD)
{
osal_start_timerEx( keyfobapp_TaskID, ADVERT_OFF_EVT, ADVERT_OFF_PERIOD );
}

if((advert_mode==1)&&( gapProfileState == GAPROLE_CONNECTED ))
{
flag=FALSE;
// operation=1;
operation_mode=0;
GAPRole_TerminateConnection();

GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &flag );
osal_stop_timerEx( keyfobapp_TaskID,ADVERT_OFF_EVT);
/osal_start_timerEx( keyfobapp_TaskID, ADVERT_ON_EVT, ADVERT_ON_PERIOD );

}
return (events ^ ADVERT_OFF_EVT);
}

if ( events & ADVERT_ON_EVT )
{
if(ADVERT_ON_PERIOD)
{
osal_start_timerEx( keyfobapp_TaskID, ADVERT_ON_EVT, ADVERT_ON_PERIOD );
}
if(operation==1) //&&(gapProfileState = GAPROLE_ADVERTISING));
{
flag=TRUE;
advert_mode=0;
operation=0;

GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &flag );

}

After executing this it is continously start connecting and disconnecting.Can anybody tell what is the procedure to follow inorder to stay connected 

Regards

Don

  • Hello Don,
    Maybe the GAPRole_TerminateConnection(); is causing the trouble?
    I think you should reserve this for GAPROLE_TERMINATE_LINK or L2CAP_CONN_PARAMS_REJECTED.
  • I'd suggest walking through that with a debugger in IAR. Perhaps you are calling for advertising to be off after a connection is established.
    You have:
    if advertising && connected:
    GAPRole_TerminateConnection(); (You may be asking for a disconnection here)
  • Hi Eirik and Carl,

    Thanks for the reply.Actually i was using immediate alert profile to disconnect.I was able to disconnect using the immediate alert code which i send from the BLE app, but it was executing the same alert again and again. so i cleared the alert after termination. Now i am able to disconnect and connect again without drop in connection.
    GAPRole_TerminateConnection();
    keyfobProxIMAlertLevel=0;
    Can you tell me why that immediate alert code is again executed after disconnection. I mean each time i send the code , while reconnecting that particular code which i send for disconnection is executed again, and so disconnecting .

    Regards
    Don