K70-TWR RTC

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

K70-TWR RTC

1,716 Views
chrislynch
Contributor I

Hi,

      I am having issues getting the RTC->TSR & RTC->TPR registers to increment on a K70-TWR board i just received.

      I have had no problem getting a K60-TWR RTC to work correctly and the code below is identical (apart from enabling RTC->IER), I am using Keil uVision.

 

void rtc_init(void)

{

  unsigned int i;

 

  /*enable the clock to SRTC module register space*/

  SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;

 

   

  /*Only VBAT_POR has an effect on the SRTC, RESET to the part does not, so you must manually reset the SRTC to make sure everything is in a known state*/

  /*clear the software reset bit*/

  RTC->CR  = RTC_CR_SWR_MASK;

  RTC->CR  &= ~RTC_CR_SWR_MASK; 

     

     /*Enable the oscillator*/

  RTC->CR |= RTC_CR_OSCE_MASK | RTC_CR_SC16P_MASK;

   

     /*Wait to all the 32 kHz to stabilize, refer to the crystal startup time in the crystal datasheet*/

// for(i=0;i<0x600000;i++);

    for(i=0;i<0x6000000;i++);//120MHz clock, so 838ms long delay for test

     

     /*Set time compensation parameters*/

    RTC->TCR = RTC_TCR_CIR(0) | RTC_TCR_TCR(0);

 

    /*Configure the timer seconds and alarm registers*/

    RTC->TSR = 0x0F;

  RTC->TAR = 0xFFFFFFFF;

   

    /*Enable Interrupts*/

    RTC->IER= RTC_IER_TIIE_MASK | RTC_IER_TOIE_MASK;

   

    /*Enable NVIC RTC interrupt*/

    NVIC_EnableIRQ(RTC_IRQn);

   

  /*Enable the counter*/

  RTC->SR |= RTC_SR_TCE_MASK;

}

void RTC_IRQHandler(void)

{

      

   if((RTC->SR & RTC_SR_TIF_MASK)== 0x01)

     {

       //printf("SRTC time invalid interrupt entered...\r\n");

          RTC->SR &= 0x07;  //clear TCE, or RTC_TSR can  not be written

          RTC->TSR = 0x00000000;  //clear TIF

     }   

   else if((RTC->SR & RTC_SR_TOF_MASK) == 0x02)

   {

          //printf("SRTC time overflow interrupt entered...\r\n");

          RTC->SR &= 0x07;  //clear TCE, or RTC_TSR can  not be written

          RTC->TSR = 0x00000000;  //clear TOF

   }        

   else if((RTC->SR & RTC_SR_TAF_MASK) == 0x04)

   {

         // printf("SRTC alarm interrupt entered...\r\n");

      //  printf("Time Seconds Register value is: %i\n", RTC_TSR);

      RTC->TAR += 1;// Write new alarm value, to generate an alarm every second add 1

   }   

   else

   {

       //printf("No valid Flag was set!\n");

   }

   return;

}

0 Kudos
5 Replies

723 Views
chrislynch
Contributor I

Agghhhhh i just swapped the crystal from my K60 to the K70 board and it worked. I just wasted my weekend :smileysad:.

Im disappointed in Freescale as its a brand new TWR board.

0 Kudos

723 Views
chrislynch
Contributor I

Just put the suspect crystal on the K60 for a test and it works, I will have to put it down to a bad joint as one of the crystal pins came away from its pad when i was heating the body of the crystal (also soldered to the pcb). So if anyone else has a similar experience try re-soldering the crystal joints.

0 Kudos

723 Views
Monica
Senior Contributor III

Chris,

I'm sorry you're having inconveniences with our products.

However, your feedback here is very important and I really appreciate you're sharing it over.

Thanks and best regards.

Monica.

0 Kudos

723 Views
chrislynch
Contributor I

I also found that RTC_IRQHandler is entered after the rtc_init function, when it enters the handler the RTC->SR value is 0x10.. Consequently it enters the last else statement of the interrupt handler. Im unsure why it enters the handler at all as the RTC->SR value is correct with no interrupt flags set.

0 Kudos

723 Views
chrislynch
Contributor I

I just scoped the external xtal and it is not oscillating, it is on the K60 with the same code. Maybe its a dud crystal?

0 Kudos