Hi,
I'm searching a way to create a function which would be a timer function (so, this function will have an int number as input parameter), and during this delay, I would like to enter the processor in sleep mode (with __WFE(); I suppose). I would like to use the RTC (32768Hz).
Can you help me to create such a function please ? I've been searching and looking on DevZone for 5 days, but I'm still searching for a solution because I've failed to do it up to now.
Thank's a lot to help me !
(I have a nRF51422 DK, and I use the softdevice s110).
Here is my current code, which doesn't work :
void rtcInit(void); void wait_us(int us); static void RTC0_IRQHandler(void);
int main(void) { NRF_POWER->TASKS_LOWPWR=1; rtcInit(); nrf_gpio_cfg_output(22); nrf_gpio_pin_set(22);
while(true) { nrf_gpio_pin_toggle(22); wait_us(1); }
}
void rtcInit() { NRF_RTC0->TASKS_STOP = 1; NRF_RTC0->PRESCALER = 0; //NRF_RTC0->INTENSET = 0x10000; // enable CC0 int NRF_RTC0->EVTENSET = 0x10000; // enable CC0 event }
void wait_us(int us) { NRF_RTC0->TASKS_STOP = 1; NRF_RTC0->TASKS_CLEAR = 1; NRF_RTC0->CC[0] = 33*us; //NRF_RTC0->CC[0] = 32768;
NRF_RTC0->INTENSET = 0x10000; // enable CC0 int
NRF_RTC0->EVTENCLR = 0x10000; // enable CC0 event
NRF_RTC0->EVTENSET = 0x10000; // enable CC0 event
NRF_RTC0->TASKS_START = 1;
__SEV();
__WFE();
__WFE();
}
static void RTC0_IRQHandler(void)
{
}