Hi there,
I'm trying to port my code from KSDK 1.0.0 to KSDK 1.3.0, using KDS 3.0.0. Device is MK22FN256xxx12.
We need a precise timer in the ms, which means we can't use "OSA_TimeGetMsec()" since it's drifting too much. In KSDK 1.0.0 we manually set the RTC registers and read them. But when I tried to port the code to KSDK 1.3.0, whenever I write 1 to the CR OSCE it will trigger some sort of "WDOG_EWM_IRQHandler()" or Default ISR.
Seems like I'm missing something here... any help is appreciated... Thanks!
This is the piece of code:
#define BP_RTC_CR_OSCE (8U) /*!< Bit position for RTC_CR_OSCE. */
#define HW_RTC_CR_ADDR(x) ((x) + 0x10U)
#define BW_RTC_CR_OSCE(x, v) (BITBAND_ACCESS32(HW_RTC_CR_ADDR(x), BP_RTC_CR_OSCE) = (v))
void k22f_enable_rtc() {
// Enable 32.768 kHz oscillator
// The following is the offending line... Ported from KSDK 1.0.0
BW_RTC_CR_OSCE(RTC, 1); //or RTC_BWR_CR_OSCE(RTC, 1)
// Wait 100ms for oscillator output to settle down
OSA_TimeDelay(100);
/* // Disable time counters TSR and TPR before writing
RTC_BWR_SR_TCE(RTC, 0);
// Clear the RTC_TPR counter
HW_RTC_TPR_CLR(RTC, 0xFFFFFFFFU);
// Write the RTC_TSR with 0 second value
RTC_WR_TSR(RTC, 0);
// Enable time counters TSR and TPR after writing
RTC_BWR_SR_TCE(RTC, 1); */
last_sec = 0;
last_tpr = 0;
last_total_ms = 0;
}
This is the result.
Solved! Go to Solution.
Hi Cecylia Wati,
From your description, it seems you didn't enable the RTC clock gate.
Please add this code before your RTC register configuration:
SIM_SCGC6|= SIM_SCGC6_RTC_MASK;
Please test it on your side, if you still have question, please kindly let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Cecylia Wati,
From your description, it seems you didn't enable the RTC clock gate.
Please add this code before your RTC register configuration:
SIM_SCGC6|= SIM_SCGC6_RTC_MASK;
Please test it on your side, if you still have question, please kindly let me know!
Have a great day,
Jingjing
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Thank you! This seems to work.
Hi
I don't think that the PE generated or KSDK code respects all real-world cases where the RTC may already be operating and have interrupts enabled. There was a problem with the PE generated code that caused issues as detailed here: https://community.nxp.com/message/515197#comment-515197
When enabling/re-enabling the RTC I would first check whether it is already running since it is a waste of time to restart it and wait if it is already operating. In addition it is always best to temporarily disable its operation to avoid it generating interrupts before you are ready for them. Use RTC_SR = 0; to do this before the initialisation code (but after the RTC module's clocks have been applied).
Regards
Mark