k60 rtc with external battery backup reinit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

k60 rtc with external battery backup reinit

931 Views
jasonscott
Contributor IV

Hi everyone,

I am struggling with the RTC on a custom board that uses the k60.

i have the 3 volt battery connected to the VBAT pin (pin 42). A 32.8 KHz crystal connected across XTAL32 & EXTAL32.

I know that the hardware is fine, this design has been in place for a few years. We have recently upgraded to MQX 4.2 using the KDS IDE without processor expert.

I am struggling with the bsp settings for the RTC. The RTC is re-initializing every time upon bootup. I would assume there is a way to have it check to see if the RTC is already running. which under the _RTC_INIT() function, it appears to do....

int32_t _rtc_init
(
/* [IN] param identifying init operations */
void* param
)
{ /* Body */
int32_t result = MQX_OK;
RTC_MemMapPtr rtc = RTC_BASE_PTR;

_int_disable();
/* Check if the time is invalid */
if (rtc->SR & RTC_SR_TIF_MASK)
{
rtc->SR &= ~RTC_SR_TCE_MASK; /* disable rtc timer - enable write access */
rtc->TAR = 0xFFFFFFFF; /* e2574: RTC: Writing RTC_TAR[TAR] = 0 does not disable RTC alarm */

/* if TIF reading TSR return zero and we must set TSR to one */
rtc->TSR = 1; /* this clear SR flags TIF, TOF */
rtc->SR |= RTC_SR_TCE_MASK;
/* Update alarm time & alarm period */

alarm_time = 0;
alarm_period = 0;
} /* End if*/
_int_enable();

/* Check if RTC counter or OSC for RTC is not started */
if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
{
rtc->CR |= RTC_CR_OSCE_MASK;
/* recommended 125 ms delay for oscillator start */
_time_delay(125);
rtc->SR |= RTC_SR_TCE_MASK;
} /* End if */

return result;
} /* Endbody */

From my understanding the RTC should continue to run off of the battery power when the main power is shut off. The only setting that is 100% clear is to set BSPCFG_ENABLE_RTCDEV to 1. 

Does anyone have an idea on where i should direct my attention to?

Thanks for you time,

J

0 Kudos
5 Replies

600 Views
jasonscott
Contributor IV

Too bad i wasn't able to get any insight from anyone on this forum....

For whomever is reading/has a similar situation.

Interesting find...

Under MQX 4.02, when the rtc driver is initialized, the rtc time is synced with the mqx time.

I was able to do something similar under 4.2, by calling the following lines of code from the user application.

uint32_t rtc_seconds;
DATE_STRUCT mqx_date;
TIME_STRUCT mqx_time;

_rtc_get_time(&rtc_seconds);
mqx_time.SECONDS = rtc_seconds;
_time_set(&mqx_time);

The clock now is not resetting to 1970, but is off 7~ minutes when i preform a power cycle. (only on the first power cycle)

BUT, from what i can tell the rtc is running off VBAT when the system is powered down. which resolved my initial issue.

0 Kudos

600 Views
mjbcswitzerland
Specialist V

Jason

I think that for MQX related questions you will find help in the MQX Software Solutions forum rather than the Kinetis (processor) forum: https://community.nxp.com/community/mqx 

From what I understand NXP no longer supports MQX but it seems there are MQX people at that forum.

Regards

Mark

600 Views
jasonscott
Contributor IV

Hi Mark,

Thanks for your input.

I wasn't aware I was posting in the wrong location.

I'll give that a look.

-Jason

0 Kudos

600 Views
jasonscott
Contributor IV

More information...

The previous version of mqx was 4.01 and we are now using mqx 4.2.

The RTC initialization under 4.01 appears to be structured differently and syncs the mqx time with the rtc time.

Can someone confirm that there are differences in operation using the RTC on version 4.01 and 4.2?

Under the release notes for version 4.02, the rtc driver states that it will be renewed during bsp startup. 

So does that mean we can no longer use the external battery power option?

pastedImage_1.png

As always, thanks for your time.

-J

0 Kudos

600 Views
jasonscott
Contributor IV

Correction. 

in my post above, i stated that i was entering this if statement.

/* Check if RTC counter or OSC for RTC is not started */
if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
{
rtc->CR |= RTC_CR_OSCE_MASK;
/* recommended 125 ms delay for oscillator start */
_time_delay(125);
rtc->SR |= RTC_SR_TCE_MASK;
} /* End if */

That is not the case. 

So if the RTC counter has already been started prior to this point (which it should be with the battery backup).

Why is the RTC counter still resetting itself to the 1970 default??

0 Kudos