RTC DeInit problem in the example code

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

RTC DeInit problem in the example code

ソリューションへジャンプ
1,438件の閲覧回数
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;
}

ラベル(2)
0 件の賞賛
返信
1 解決策
1,278件の閲覧回数
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,279件の閲覧回数
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 件の賞賛
返信