The test code:
#include "nrf51.h"
int main(void) {
NRF_CLOCK->LFCLKSRC = 0UL; // Internal 32kHz RC
// Start the 32 kHz clock, and wait for the start up to complete
NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
NRF_CLOCK->TASKS_LFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
// Configure the RTC to run at 2 second intervals, and make sure COMPARE0 generates an interrupt (this will be the wakeup source)
NRF_RTC1->PRESCALER = 0;
NRF_RTC1->EVTENSET = 0x1UL;
NRF_RTC1->INTENSET = 0x1UL;
NRF_RTC1->CC[0] = 10*32768;
NVIC_EnableIRQ(RTC1_IRQn);
// Start the RTC timer
NRF_RTC1->TASKS_START = 1;
// Enter System ON sleep mode
__WFE();
// Make sure any pending events are cleared
__SEV();
__WFE();
// Stop and clear the RTC timer
// NRF_RTC1->TASKS_STOP = 1;
// NRF_RTC1->TASKS_CLEAR = 1;
}
void RTC1_IRQHandler(void)
{
// This handler will be run after wakeup from system ON (RTC wakeup)
if(NRF_RTC1->EVENTS_COMPARE[0]) {
NRF_RTC1->EVENTS_COMPARE[0] = 0;
NRF_RTC1->TASKS_CLEAR = 1;
}
}
Any advice? datasheet says the RTC current should be 0.1uA....