Switch to RTC on first power on with K60

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch to RTC on first power on with K60

466 Views
norton256
Contributor III

I have four custom K60 designs where I need to switch to the RTC as my main input clock relatively early in the boot process.

Currently I attempt to switch, and then monitor the loss of clock bit. If it goes high I clear it and retry.

For the first time that both prime and battery power are applied, the K60 can never seem to successfully switch to the RTC. After prime power is cycled, and battery remains, the switch occurs without any problems.

What is the reason why the clock monitor has issues with the RTC the first power on?

Thanks!

Labels (1)
Tags (2)
0 Kudos
4 Replies

209 Views
norton256
Contributor III

That is already done before the code I pasted before:

switch(clockSwitchParams.ClockSource)
{
case Clocking_RTC:
{
SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;

RTC_CR |= RTC_CR_OSCE_MASK;
RTC_CR &= ~RTC_CR_CLKO_MASK;

break;
}
case Clocking_Osc0External:
{
if (!module->Osc0Initialized)
{
// configure the MCG_C2 register
// the RANGE value is determined by the external frequency. Since the RANGE parameter affects the FRDIV divide value
// it still needs to be set correctly even if the oscillator is not being used

temp_reg = MCG_C2;
temp_reg &= ~(MCG_C2_RANGE_MASK | MCG_C2_HGO_MASK | MCG_C2_EREFS_MASK); // clear fields before writing new values

temp_reg |= MCG_C2_RANGE(1);

MCG_C2 = temp_reg;

// Enable the external reference sourced from OSC0
OSC0_CR |= 0x80;

module->Osc0Initialized = TRUE;
}
break;
}
}

Hence my confusion. Is there something odd about the startup time requirement? If the clock is monitored before that expires it is forever wacky?

0 Kudos

209 Views
norton256
Contributor III

I am using the MK60FN1M0VMD12.

The code for the full clock transition module is pretty big. I use many of the MCG modes in our application.

The particular mode where this gets stuck is a switch from FEI (default) mode to FBE (yes, I am trying to run at 32 kHz).

I am using a crystal connected to Extal32/Xtal32.

The location where my clock switch code gets stuck is here:

if (nextClockSource == Clocking_RTC)
{
// disable OSC0 monitor
MCG_C6 &= ~MCG_C6_CME_MASK;
// disable OCS1 monitor
MCG_C12 &= ~MCG_C12_CME2_MASK;
// enable RTC monitor
MCG_C8 |= MCG_C8_CME3_MASK;

while(1) <----------------- stuck in this loop!!!!!
{
if ((MCG_C8 & MCG_C8_LOCS3_MASK) == 0)
{
break;
}
else
{
MCG_C8 |= MCG_C8_LOCS3_MASK;
for(j = 0; j < 1000000; ++j); // delay
i++;
}
}
}

before this I set the clock monitor to interrupt instead of reset, and I disable the Monitor Interrupt Vector so that I can poll. At this point I have only enabled the RTC, the MCU is still in FEI mode.

Thanks!

0 Kudos

209 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Although I do not have a test, I think you can try the following code.

If you use FBE mode with 32K crystal with Extal32/Xtal32 pins, you have to set the OSCE bit in RTC_CR reg.

RTC_CR|=0x100;

MCG_C8 |= MCG_C8_CME3_MASK;

while(1) <----------------- stuck in this loop!!!!!
{
if ((MCG_C8 & MCG_C8_LOCS3_MASK) == 0)
{
break;
}

Pls have a try.

BR

Xiangjun Rong

0 Kudos

209 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Nick,

What is the part number you are using now?

Do you want to route the external clock or crystal signal from Extal32/Xtal32 to the FLL so that you can use FEE mode for MCG module? If it is the case, can you past the code here so that we can have a review?

Do you use crystal or clock source for the Extal32/Xtal32?

BR

Xiangjun Rong

0 Kudos