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??