This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to restart ble when it is connect on nrfconnect app on mobile without reaching the breakpoint?

Hi Everyone ,

I have setup an gpiote iinterrupt on a button on a custom PCB incorporating nrf52840.
Whenever the interrupt arrives(button pressed) the bluetooth shall wake up from its sleep(start advertising again).

i am able to do this but partially.
When the nrf52840 ble is not connected with android app(nrfconnect) , the ble wakes up fine without any errors.

But in the scenario where ble of nrf52840 is connected with the nrfconnect app and button is pressed, The code reaches a breakpoint resulting is restart of the board after sometime.
Here's the code inside the interrupt handler.

void
in_pin_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{

sd_ble_gap_adv_stop (NULL);

advertising_start ();

}

void advertising_start(void)
{
uint32_t err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
}

Parents
  • Update  : I have setup flags for both the status , whenever ble is connected or is in sleep mode.

    Modified code is 


    void
    in_pin_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {

    SEGGER_RTT_printf (0, "Interrupt\r\n");

    if(connected_ble_flag !=1)
    {
    sd_ble_gap_adv_stop (NULL);

    advertising_start ();
    }
    else if(ble_sleep==1)
    {
    sd_ble_gap_adv_stop (NULL);

    advertising_start ();
    }

    If there are any modification needed or there is a better way to do it , please provide suggestions

    thanks

Reply
  • Update  : I have setup flags for both the status , whenever ble is connected or is in sleep mode.

    Modified code is 


    void
    in_pin_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {

    SEGGER_RTT_printf (0, "Interrupt\r\n");

    if(connected_ble_flag !=1)
    {
    sd_ble_gap_adv_stop (NULL);

    advertising_start ();
    }
    else if(ble_sleep==1)
    {
    sd_ble_gap_adv_stop (NULL);

    advertising_start ();
    }

    If there are any modification needed or there is a better way to do it , please provide suggestions

    thanks

Children
Related