Hello ,
I am working on the development kit nrf52, i want to know how i canget the value of the RTC overflw and then how i can reset the RTC to zero.
thank you in advance
Best regards
Hello ,
I am working on the development kit nrf52, i want to know how i canget the value of the RTC overflw and then how i can reset the RTC to zero.
thank you in advance
Best regards
You cannot get the overflow value but you can get an overflow event in EVENTS_OVERFLW register. For this you have to enable this event in RTC->EVTEN register.
You then need to enable interrupt for this in the INTENSET and increment a static variable everytime you get the overflow event. After incrementing the variable, you clear the overflow event.
for example in the RTC interrupt handler you can do something like this
static uint8_t tick_overflow_count = 0; /* check for overflow in RTC counter */ if(nrf_rtc_event_pending(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW)) { nrf_rtc_event_clear(portNRF_RTC_REG, NRF_RTC_EVENT_OVERFLOW); tick_overflow_count++; } // then you get the full value uint32_t systick_counter = nrf_rtc_counter_get(portNRF_RTC_REG); full_value = ((tick_overflow_count << portNRF_RTC_BITWIDTH) + systick_counter);
Hello Aryan ,
Thank you for respond.
I want to reset the rtc by a extern interruption (accelerometer), i want to know which function can i use?
Thank you in advance.
rtc1 OR rtc2? Your code seems to initialize rtc1 but looks for an event on rtc2.
I initialised the rtc2 , just i use the name rtc1
1) You are initializing RTC1 and checking for RTC2 events in ISR. You need to check RTC1 events in ISR.
2)
if(NRF_RTC2->EVENTS_OVRFLW==1) { NRF_RTC2->TASKS_CLEAR = 1; sd_power_system_off(); printf("overflw"); }
printf will never be executed since the sd_power_system_off will never return. Any wakeup will reset the chip. If you want to return here, then use sd_app_evt_wait() instead of system off.
thanks ,
I initialised the RTC 2 (const nrf_drv_rtc_t rtc1 = NRF_DRV_RTC_INSTANCE(2); /**< Declaring an instance of nrf_drv_rtc for RTC2. */)
the problem is the system does not go into sleep mode
1) enable the overflow event and interrupt
You forgot to clear the even in RTC2 ISR, but that cannot be the reason for the system not to go to deep sleep. Also move the printf to the start of the condition.
if(NRF_RTC2->EVENTS_OVRFLW==1)
{
printf("overflw");
NRF_RTC2->EVENTS_OVRFLW = 0;
NRF_RTC2->TASKS_CLEAR = 1;
sd_power_system_off();
}
This is very basic thing to work. Please look at the SDK examples to see how this things work
1) enable the overflow event and interrupt
You forgot to clear the even in RTC2 ISR, but that cannot be the reason for the system not to go to deep sleep. Also move the printf to the start of the condition.
if(NRF_RTC2->EVENTS_OVRFLW==1)
{
printf("overflw");
NRF_RTC2->EVENTS_OVRFLW = 0;
NRF_RTC2->TASKS_CLEAR = 1;
sd_power_system_off();
}
This is very basic thing to work. Please look at the SDK examples to see how this things work