RTC problem with kl46z

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

RTC problem with kl46z

Jump to solution
2,461 Views
floridjam
Contributor II

Hi every body,

I'am a newbe with my kl46z board and I try to generate an one second interruption with the RTC. Here is the program :

//test
MCG_C1 |= MCG_C1_IRCLKEN_MASK;
MCG_C2 &= ~(MCG_C2_IRCS_MASK);
//Enable Clock for RTC
SIM_SCGC6 |= SIM_SCGC6_RTC_MASK;

//Enable interrupt second
RTC_IER |= 0x10;
RTC_IER &= 0xfffffff8;
NVIC_EnableIRQ(21);
//Chose Clk OSC32KCLK
SIM_SOPT1 |= 0x00000000;

//ENable OSCE
RTC_CR |= 0x100;

//To clear the Time invalid Flag
RTC_TSR =0x01;
//Enable RTC
RTC_SR |= 0x10;

But at the end I never go to interruption. If you have any idea that could help me please ?

0 Kudos
1 Solution
1,828 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Florian,

According to your last Question, it seems that you are using FRDM-KL46Z freedom board.

The RTC module has three clock sources.

RTC clock generation.png

This board has a 8MHz crystal connected on System oscillator, but 8MHz OSC32KCLK can't be used for RTC.

And there is no 32kHz clock source connected on RTC_CLKIN.

FRDM-KL46Z RTC clock source.png

In order to evaluation RTC second interrupt on FRDM-KL46Z, you may have to select internal 1kHz LPO as the clock source of RTC. Due to the lower frequency of clock source, The RTC second interrupt may happen every 32s.

internal 1kHz LPO.png

Best Regards,

Robin

View solution in original post

5 Replies
1,828 Views
floridjam
Contributor II

Thank you Mark.

0 Kudos
1,828 Views
floridjam
Contributor II

Yes ! It work with the LPO. But now how can I manage to have a 1s interruption instead of every 32 seconds. May be I should use a timer to do so ?

Anyway thanks a lot for your answer.

0 Kudos
1,828 Views
mjbcswitzerland
Specialist V

Hi

The following is the code to allow the LPO to be used as 1s interrupt:

    RTC_SR = 0;  // temporarily disable RTC to avoid potential interrupt
    RTC_TPR = (32768 - 1000);  // use 1kHz internal clock to generate 1s time base by adjusting the prescaler value
    RTC_SR = RTC_SR_TCE;  // enable counter again

It needs to be performed when starting and at each 1s interrupt.

Note however that the LPO is not very accurate and so will tend to get up to 1 minute drift every hour. If you have a real-world RTC requirement you usually need to use a 32kHz oscillator.
Also the LPO will cause the RTC to be 32x too slow when the chip is in the very low power mode and so any alarms etc. will be inaccurate unless compensated for in the software solution.

I have attached the uTasker RTC module as reference (for all chips, including KLs) which also solves KL RTC with LPO source with regards to keeping time in standby modes and with regards to low power wake up alarms.

Regards


Mark
Kinetis for professionals: http://www.utasker.com/kinetis.html

1,829 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Florian,

According to your last Question, it seems that you are using FRDM-KL46Z freedom board.

The RTC module has three clock sources.

RTC clock generation.png

This board has a 8MHz crystal connected on System oscillator, but 8MHz OSC32KCLK can't be used for RTC.

And there is no 32kHz clock source connected on RTC_CLKIN.

FRDM-KL46Z RTC clock source.png

In order to evaluation RTC second interrupt on FRDM-KL46Z, you may have to select internal 1kHz LPO as the clock source of RTC. Due to the lower frequency of clock source, The RTC second interrupt may happen every 32s.

internal 1kHz LPO.png

Best Regards,

Robin

1,828 Views
mjbcswitzerland
Specialist V

Hi

http://www.utasker.com/kinetis/KL_RTC.html
http://www.utasker.com/docs/uTasker/uTasker_Time.pdf
http://www.utasker.com/kinetis/FRDM-KL46Z.html
http://www.utasker.com/kinetis/TWR-KL46Z48M.html

Explications and code for KL46 RTC, including a complete Gregorian calendar implementation, SNTP, alarms, alarm wake-up from very low power mode, summer time and time zone management.

Regards

Mark
Kinetis for professionals: http://www.utasker.com/kinetis.html