RTC problem with kl46z

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

RTC problem with kl46z

跳至解决方案
3,725 次查看
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 项奖励
回复
1 解答
3,092 次查看
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

在原帖中查看解决方案

5 回复数
3,092 次查看
floridjam
Contributor II

Thank you Mark.

0 项奖励
回复
3,092 次查看
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 项奖励
回复
3,092 次查看
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

3,093 次查看
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

3,092 次查看
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