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

Problem with advertising reset

Hi, I try to turn off the advertising after the first connection and then turn it on after pressing the button, this is what I wrote:

void radio_notification_evt_handler(bool radio_evt)
{
    if (radio_evt)
    {
		//radio going active
		LEDS_INVERT(BSP_LED_1_MASK);
		if (connection_occurance) sd_ble_gap_adv_stop();
    } 
}

//

void GPIOTE_IRQHandler(void)
{
		printf("Are you here?");
		ble_advertising_start(BLE_ADV_MODE_FAST);
		if(NRF_GPIOTE->EVENTS_PORT)
                   		NRF_GPIOTE->EVENTS_PORT = 0;
}

Program comes to the handler of button interrupt but there the program is crashing. This problem is quite suprising for me, because I reset advertising in other application and there it's work well. Only difference is that in the other case I turn off and immediately turn on advertising, and in this application I wait for button.

  • As far as i know, advertising is automatically stopped after connection. You sure you need to stop it manually?

  • Yes, you are right, my mistake. Function ble_advertising_on_ble_evt in ble_evt_dispatch starts the advertising after connection end and after I remove this function I don't need to stop advertising manually. However, I still can't start advertising in GIOTE_IRQHandler, and I don't know why. Beneath I placed sys_evt_dispatch and ble_evt_dispatch, maybe there is a reason why it not working (in fact I have trouble to fully understand these functions, particularly when these functions are calling)

    static void ble_evt_dispatch(ble_evt_t * p_ble_evt)
    {
        dm_ble_evt_handler(p_ble_evt);
        ble_conn_params_on_ble_evt(p_ble_evt);
        on_ble_evt(p_ble_evt);
        ble_our_service_on_ble_evt(&m_our_service, p_ble_evt);
    }
    
    
    static void sys_evt_dispatch(uint32_t sys_evt)
      {
            pstorage_sys_event_handler(sys_evt);
            ble_advertising_on_sys_evt(sys_evt);
            if (sys_evt == NRF_EVT_POWER_FAILURE_WARNING)
            {
        	sd_power_dcdc_mode_set(NRF_POWER_DCDC_DISABLE);
            }
        }
    
  • I am not familiar with advertising module (i just don't use it to advertise), but i think this is because you cannot call SVC from higher priority context. I assume your GPIOTE IRQ have higher priority than SVC, so it causes hardfault. You just have to leave somehow from interrupt context (just set a flag in irq handler?) and start advertising by checking the flag. about ble_evt_dispatch and sys_evt_dispatch - they are used to propagate BLE and SOC events in app, you can read about it here and here

  • Thank you! I changed priority to 3 and now everything works fine :)

Related