Hi there,
I've recently purchased a nrf9160dk to evaluate. I've got some demo code going connecting via LTE and chatting to my AWS server via TCP and that's all going well. For my purposes I want to wake the device up once every 5 minutes to sample a sensor and go back to sleep between these samples. Only a few times a day I intend on sending this data to my server as the device will be battery powered and I want it to last as long as possible.
I'm struggling however with figuring out how I put the device into a sleep mode, ideally the lowest possible while allowing the RTC to still operate. Does anyone have any demo code that shows how to set the RTC up to wake the device from a low powered sleep? I'm unaware at this point of how to even put the device into a sleep mode, I've only encountered `nrf_regulators_system_off(NRF_REGULATORS_NS);` which I can use to power the whole unit off but by that stage the RTC doesn't seem to wake the system.
My code currently looks something like this:
#define COMPARE_COUNTERTIME 3
static void rtc_handler(nrfx_rtc_int_type_t int_type) {
if (int_type == NRFX_RTC_INT_COMPARE0) {
nrf_gpio_pin_toggle(LED_0);
}
}
static void rtc_config(void) {
uint32_t err_code;
nrfx_rtc_config_t config = NRFX_RTC_DEFAULT_CONFIG;
config.prescaler = 4095;
err_code = nrfx_rtc_init(&rtc, &config, rtc_handler);
if (err_code != NRFX_SUCCESS) {
printk("Failure in setup\n");
return;
}
err_code = nrfx_rtc_cc_set(&rtc, 0, COMPARE_COUNTERTIME * 8, true);
if (err_code != NRFX_SUCCESS) {
printk("Failure in setup\n");
return;
}
nrfx_rtc_enable(&rtc);
}
void main(void) {
int err;
err = bsdlib_init();
if (err) {
printk("Failed to initialize bsdlib!");
return;
}
rtc_config();
IRQ_DIRECT_CONNECT(RTC0_IRQn, 0, nrfx_rtc_0_irq_handler, 0);
irq_enable(RTC0_IRQn);
bsdlib_shutdown();
nrf_regulators_system_off(NRF_REGULATORS_NS);
}
Any help would be greatly appreciated,
Thanks,
Josh