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

Disable bluetooth during GPIO interruption

Hi!

I'm working with a NRF51822 (not a dev card) and I want to disable and enable BLE by switching a switch. I've been looking at this thread and the functions bluetooth_sleep() and bluetooth_wake() work perfectly when used in the while(1) loop like this :

while(1)
  {
    while(!nrf_gpio_pin_read(GPIO_SWITCH));
    advertising_start();
    nrf_gpio_pin_clear(GPIO_LED);
    while(nrf_gpio_pin_read(GPIO_SWITCH));
    bluetooth_sleep();
    nrf_gpio_pin_set(GPIO_LED);

My interruption looks like this and is working well when I'm doing small stuff like toggling LEDs :

void GPIOTE_IRQHandler(){
      if(NRF_GPIOTE->EVENTS_PORT)
        NRF_GPIOTE->EVENTS_PORT = 0;
      if(nrf_gpio_pin_read(GPIO_SWITCH)){
        nrf_gpio_cfg_sense_input(GPIO_SWITCH, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
        nrf_gpio_pin_set(GPIO_LED);
      }
      else{
        nrf_gpio_cfg_sense_input(GPIO_SWITCH, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
        nrf_gpio_pin_clear(GPIO_LED);
      }    
    }
}

But whenever I replace the nrf_gpio_pin_clear or set by bluetooth_sleep() and the start_advertising() functions in my GPIO interruption, it doesn't work. I've been turning on and off LEDs before using the functions and it seems the microcontroller gets always stuck when it has to turn the bluetooth on or off.

Here's my interruption activation, just in case:

  nrf_gpio_cfg_sense_input(GPIO_PUSH_BUTTON, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
  NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
  NVIC_EnableIRQ(GPIOTE_IRQn);

If someone could give me a hint!

Thanks

Hugo B.

Related