NRF52833 SLEEP MODE & WAKEUP THROUGH GPIO INTERRUPT.

Hi All,

         I have implemented sleep mode in the firmware. I am using NRF52833 in my project. When the device is in idle state it goes in sleep mode. Now I wanted to wakeup the device through GPIO interrupt. How can I wake up the device? The sleep mode is implemented as below in the attached code.

#define AQ_USER_BUTTON          NRF_GPIO_PIN_MAP(0,4)


void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
//bool erase_bonds;
   switch(pin)
   {
      case AQ_USER_BUTTON:
              NRF_LOG_INFO("ADVERTISING START\r\n");
              advertising_start(false);
            break;
   }

}

 void gpio_init(void)
{
    ret_code_t err_code;

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(AQ_USER_BUTTON, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(AQ_USER_BUTTON, true);

}


static void sleep_mode_enter(void)
	{
	  ret_code_t err_code;
	  sleep = 1;
	  NRF_LOG_INFO("SLEEP MODE ENTER\r\n");
	  err_code = bsp_indication_set(BSP_INDICATE_IDLE);
	  APP_ERROR_CHECK(err_code);

	  // Prepare wakeup buttons.
	  err_code = bsp_btn_ble_sleep_mode_prepare();
	  APP_ERROR_CHECK(err_code);

	  // Go to system-off mode (this function will not return; wakeup will cause a reset).
	  err_code = sd_power_system_off();
	  // APP_ERROR_CHECK(err_code);
}

static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
		uint32_t err_code;

		switch (ble_adv_evt) {
		case BLE_ADV_EVT_FAST:
		NRF_LOG_INFO("Fast advertising.");
		err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
		APP_ERROR_CHECK(err_code);
		break;

		case BLE_ADV_EVT_IDLE:
		sleep_mode_enter();
		break;

		default:
		break;
}
}





Is my code correct? what code needs to be put to wakeup the device from sleep mode and then advertise it again??

Parents
  • Hi,

    I'm not sure if using GPIOTE_CONFIG_IN_SENSE_TOGGLE() will give you the intended behavior. If you are using a button to generate the interrupt, this will trigger the handler both on push and release of the button, which will try to call advertising_init() two times. This may generate error codes and restarts, as the advertising is already started from the button push. If your signal comes from a switch or another device that only generates 1 signal, it may work. You should either way make sure that you keep track of when the advertising is enabled, and only try to enable it when it is not already enabled.

    If you are using a push-button, I would recommend that you rather use GPIOTE_CONFIG_IN_SENSE_LOTOHI() or GPIOTE_CONFIG_IN_SENSE_HITOLO based on your button connections and desired behavior.

    Best regards,
    Jørgen

  • Hi Jørgen,

               Thanks for your reply. I tried to change the setting to GPIOTE_CONFIG_IN_SENSE_LOTOHI. After doing this also I am observing it gets interrupt twice and device throws error on 2nd advertising. For this I added one check point flag and if that flag is set only then I advertise. But after adding that the interrupt is not detected when i press the switch button.

    What might be wrong?

Reply
  • Hi Jørgen,

               Thanks for your reply. I tried to change the setting to GPIOTE_CONFIG_IN_SENSE_LOTOHI. After doing this also I am observing it gets interrupt twice and device throws error on 2nd advertising. For this I added one check point flag and if that flag is set only then I advertise. But after adding that the interrupt is not detected when i press the switch button.

    What might be wrong?

Children
No Data
Related