I have two questions:
Question 1: What is the timer timeout limit on nRF51822?
The reason I ask is that I want to update the advertising packet periodically. Below are part of the related code in main.c:
#define APP_TIMER_PRESCALER 0
#define APP_TIMER_MAX_TIMERS (2+BSP_APP_TIMERS_NUMBER)
#define APP_TIMER_OP_QUEUE_SIZE 4
#define ADV_INTERVAL_IN_MS (5*60000)
#define ADV_INTERVAL MSEC_TO_UNITS(ADV_INTERVAL_IN_MS, UNIT_0_625_MS)
#define ADVDATA_UPDATE_INTERVAL APP_TIMER_TICKS(ADV_INTERVAL_IN_MS, APP_TIMER_PRESCALER)
static app_timer_id_t m_advdata_update_timer;
static void timers_init(void)
{
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
uint32_t err_code = app_timer_create(&m_advdata_update_timer, APP_TIMER_MODE_REPEATED, advdata_update_timer_timeout_handler);
APP_ERROR_CHECK(err_code);
}
static void timers_start(void)
{
uint32_t err_code = app_timer_start(m_advdata_update_timer, ADVDATA_UPDATE_INTERVAL, NULL);
APP_ERROR_CHECK(err_code);
}
void advdata_update_timer_timeout_handler(void * p_context)
{
advertising_init();
}
In this code I use the internal RC oscillator, and the timer timeout handler will execute once every 5 minutes. However, if the timer is 16 bit, and timer prescaler is set to 0, the timeout limit will be 2^16/32e3 ~ 2s, which is far less than 5 minutes. At the same time, if I change it to longer value (like 20 minutes), the advertising packet will not get updated and will remain the initial value when nRF51822 was first powered on. I am a little confused.
Question 2: I want to make nRF51822 only advertise for 1 minute every hour and sleep for the rest of the time. I read RTCs and timers may be able to do this while RTC is more power efficient. Is there any example available? Another question is, if the system is in deep sleep mode, can it be waken up by RTC rather than an external GPIO interrupt? (How?)