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: How do advertising while the button is pressed?

Part Number: CC2541
Other Parts Discussed in Thread: BLE-STACK

Hi.

I am using a SimpleBLECentralBroadcaster example (1.4.2.2 BLE-Stack, IAR)

This code are working properly (when press the button once - advertising starts; when press the button again - adverising stops)

-------------------------------------------------------------

// Advertising
if ( keys & HAL_KEY_SW_1 )
{
P0_6 = 0; // Led off
// pressing the right key should toggle advertising on and off

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 );
}

-----------------------------------------------------

But in my device I want it advertise while the button is pressed and stop advertising when the button release.

Please help me with that.

Thank you.

  • Hello Pavel,

    The keys driver is configured to work on a toggle, that is a press/release triggers the action. You'll need to look at the key driver source and modify it to work on press/release. I don't believe we have an example of this behavior, but all the required source code is provided in the respective driver files.

    Best wishes
  • CC254x IO interrupt only works on single edge which could be rising or falling. Let's say your button is registered to trigger interrupt when there is a falling edge and send key event to xxx_handlekey callback. You can enable advertising in the handlekey callback and start a periodic event to check if button is released. If periodic event detects button release, you can stop advertising.