RTC DeInit problem in the example code

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

RTC DeInit problem in the example code

跳至解决方案
1,446 次查看
fanziyu
Contributor IV

Hi,everyone! 

I found a problem when I referred to the example code. the codes "while(RTC->MOD)" will spend more than 1 second.I use the oscilloscope to observe in my project .Could you help me?

mcu:keazn8

example code:

void RTC_DeInit(void)

{

   Disable_Interrupt(RTC_IRQn);

   RTC->MOD = 0;

   while(RTC->MOD);

   if(RTC_GetFlag())

  {

      RTC_ClrFlags();

   }

  RTC->SC = 0;

  while(RTC->SC);

  SIM->SCGS &= ~SIM_SCGC_RTC_MASK;

}

My code:

void RTC_DeInit(void)
{
      Disable_Interrupt(RTC_IRQn);

      RTC_MOD = 0;
      while(RTC_MOD);      
      if(RTC_SC_RTIF_MASK == (RTC_SC & RTC_SC_RTIF_MASK))
      {
            RTC_SC |= RTC_SC_RTIF_MASK;
       }

      RTC_SC = 0; 
      while(RTC_SC);
      SIM_SCGC &= ~SIM_SCGC_RTC_MASK;
}

0 项奖励
回复
1 解答
1,286 次查看
mjbcswitzerland
Specialist V

Hi

A write to the RTC modulo register is latched until the RTC counter overflows

To avoid the code blocking you can use the RTC interrupt to inform you when it has completed this "parking" of the timer so that it is in its reset state again.

You might like to also try changing the clock source in RTC_SC after setting the module to 0 since it states that doing this will clear both the module and counter, which may then be instantaneous.

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html

Kinetis KEA128:
- http://www.utasker.com/kinetis/TRK-KEA128.html
- http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html

uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

https://community.nxp.com/thread/512558

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,287 次查看
mjbcswitzerland
Specialist V

Hi

A write to the RTC modulo register is latched until the RTC counter overflows

To avoid the code blocking you can use the RTC interrupt to inform you when it has completed this "parking" of the timer so that it is in its reset state again.

You might like to also try changing the clock source in RTC_SC after setting the module to 0 since it states that doing this will clear both the module and counter, which may then be instantaneous.

Regards

Mark

Complete Kinetis solutions for professional needs, training and support: http://www.utasker.com/kinetis.html

Kinetis KEA128:
- http://www.utasker.com/kinetis/TRK-KEA128.html
- http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html

uTasker: supporting >1'000 registered Kinetis users get products faster and cheaper to market

Request Free emergency remote desk-top consulting at http://www.utasker.com/services.html

Open Source version at https://github.com/uTasker/uTasker-Kinetis

https://community.nxp.com/thread/512558

0 项奖励
回复