I am trying to wake my processor from sleep after issuing the sd_app_evt_wait(); Using an interrupt on an external RTC chip, I send interrupt pulses to the nRF at 1Hz. At startup, I have the softdevice advertise for 5 seconds then perform power management(based off the HRM example) by shutting down the spi and twi busses and the application timers for the simulated data (again, all in the HRM example). So what I see is that the LED08 in the RTC interrupt handler toggles at 1Hz as expected. Also expected is the LED1 toggling as other timer interrupts are firing, and releasing the block of sd_app_evt_wait() within power_manage().
When advertising expires, LED1 stops toggling, but LED8 (within the interrupt handler) keeps toggling. It almost seems that there is no signal to unblock sd_app_evt_wait();. Clearly I am getting interrupts, but it doesnt seem to be configured correctly to unblock sd_app_evt_wait(); in main.
Can anyone point me in the right direction?
Appropiate parts of my code is as follows:
void rtc_int_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
nrf_gpio_pin_toggle(LED08);
}
void interrupt_pin_init(void) // put after nrf_drv_gpiote_init() in main
{
ret_code_t err_code;
err_code = nrf_drv_gpiote_init();
//APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
in_config.pull = NRF_GPIO_PIN_PULLUP;
err_code = nrf_drv_gpiote_in_init(RTC_INT, &in_config, rtc_int_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_gpiote_in_event_enable(RTC_INT, true);
}
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();
APP_ERROR_CHECK(err_code);
}
int main(void)
{
uint32_t err_code;
bool erase_bonds;
//set lf clock to use 32Khz xtal
NRF_CLOCK->TASKS_LFCLKSTOP = 1;
NRF_CLOCK->LFCLKSRC = CLOCK_LFCLKSRC_SRC_Xtal;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(!NRF_CLOCK->EVENTS_LFCLKSTARTED); //wait for LFCLOCK start
//set HF clock to use 32MHz xtal
NRF_CLOCK->XTALFREQ = 0x00;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while(!NRF_CLOCK->EVENTS_HFCLKSTARTED); //wait for our HFCLOCK
// Initialize.
app_trace_init();
timers_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
device_manager_init(erase_bonds);
db_discovery_init();
gap_params_init();
advertising_init();
services_init();
sensor_simulator_init();
conn_params_init();
gpio_pin_init();
err_code = nrf_drv_spi_init(&m_spi_master, &spi0_config, spi_master_event_handler);
APP_ERROR_CHECK(err_code);
external_spi_RTC_init();
// Start execution.
nrf_delay_ms(2000);
interrupt_pin_init();
application_timers_start();
err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
APP_ERROR_CHECK(err_code);
// Enter main loop.
for (;;)
{
power_manage();
nrf_gpio_pin_toggle(LED01);
}
}