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 GAP Link Terminated: status=0 h=0 reason=0x08

Other Parts Discussed in Thread: CC2541

Hello! I use cc2541 keyfob for my application. I need to regisry a short pressure and long pressure of button. For this task i made next code modifications:

static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys )
{
uint8 SK_Keys = 0;

VOID shift; // Intentionally unreferenced parameter

if ( keys & HAL_KEY_SW_1 )
{
SK_Keys |= 0x07;
}

if ( keys & HAL_KEY_SW_2 )
{

SK_Keys |= 0x06;

// if device is not in a connection, pressing the right key should toggle
// advertising on and off
// Note: If PLUS_BROADCASTER is define this condition is ignored and
// Device may advertise during connections as well.
#ifndef PLUS_BROADCASTER
if( gapProfileState != GAPROLE_CONNECTED )
{
#endif // PLUS_BROADCASTER
uint8 current_adv_enabled_status;
uint8 new_adv_enabled_status;

//Find the current GAP advertisement status
GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, &current_adv_enabled_status );

if( current_adv_enabled_status == FALSE )
{
new_adv_enabled_status = TRUE;
}
else
{
new_adv_enabled_status = FALSE;
}

//change the GAP advertisement status to opposite of current status
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status );
#ifndef PLUS_BROADCASTER
}
#endif // PLUS_BROADCASTER
}
if (SK_Keys == 0)
{
goto m1;
}

for (uint32 i=0; i<65535*2; i++)
{
uint8 halkey = HalKeyRead();
if (halkey!=0)
{
if (i == 65534*2)
{
SK_Keys = 0x11;
goto m2;
}
}
else
{
if (halkey == 0)
{
SK_Keys = 0x22;
goto m2;
}
}
}

So i made a cycle which get a variable "uint32 i" and increment it from 0 to 65535*2. If it goes to the end, app notify 0x11 key notification, if not, then app notify 0x22. It works, but i need to do more time interval. This program realise 1 second interval for long press, but i need a 2 seconds. SO if i increase variable "i" (for (uint32 i = 0; i<65535*4; i++)), after button press, keyfob stops working and disconnect with error GAP Link Terminated: status=0 h=0 reason=0x08 and i think it is in close cycle, because it doesn't set in advertise after key press. So could you tell me, what is wrong? Should i use any timers and which timers should i use?
Or it's wrong type of variable "i"?