Hello,
I'm using: nRF51422-QFAA E00 and SDK - nRF51 5.2.0
Right now I'm running without softdevice enabled. I'm trying to use RTC1 Timer for my own delay_ms() function. I know you have app_timer and scheduler for that but I don't want to use it now.
My 1st question is about init of RTC1 with IRQ. I'm not using PPI at all so I don't need to have enabled EVENT, right? But in your examples before you set INTENSET you always set coresponding EVTENSET. Is it necessary in my case too? I don't want event for that, just jump to IRQ handler. As I tried it works even without EVTENSET line but I'm not sure if it's safe. My code for that is:
void V_hw_rtc_init(void)
{
NRF_RTC1->PRESCALER = RTC1_PRESCALER;
NRF_RTC1->CC[0] = RTC1_CC0;
NVIC_SetPriority(RTC1_IRQn, APP_IRQ_PRIORITY_LOW);
//NRF_RTC1->EVTENSET = RTC_EVTEN_COMPARE0_Msk; // Event has to be enabled for IRQ generation?
NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk;
NVIC_ClearPendingIRQ(RTC1_IRQn);
NVIC_EnableIRQ(RTC1_IRQn);
}
2nd question: Counter is incrementing during IRQ handler is proceed (at least uLINK2 debuger says). My CC[0] has value only 6. Even if update of CC[0] is last line at IRQ handler the counter will be bigger before it will quit IRQ handler, so Compare Event was not generated and my code stucked - was waiting to counter overflow. I tried even calling TASK_CLEAR but again counter increased much more than CC[0] before IRQ handler quit, but at least it set compare flag and IRQ was called again in this case.
void RTC1_IRQHandler(void)
{
if (NRF_RTC1->EVENTS_COMPARE[0] != 0)
{
if(U32_delay_ms) U32_delay_ms--; // used in V_hw_delay_ms()
NRF_RTC1->EVENTS_COMPARE[0] = 0;
NRF_RTC1->TASKS_CLEAR = 1; // Clear Counter
//NRF_RTC1->CC[0] += RTC1_CC0;
}
}
Is there some workaround different than setting lower prescaler and higher CC ?