RTC DeInit problem in the example code

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

RTC DeInit problem in the example code

Jump to solution
787 Views
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 Kudos
1 Solution
627 Views
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

View solution in original post

0 Kudos
1 Reply
628 Views
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 Kudos