Class for the RTC module.

Dependents:   FRDM_RTC

Please pay attention

This library works only with the FRDM board connected to USB via OpenSDA connector The OpenSDA chip has a pin connected, via the resistor R24, to the KL25Z CLOCKIN pin. So this is why it works.

If you use the board alone, you must configure the MCU in a different manner. I follow the instruction in this link: https://community.freescale.com/docs/DOC-94734 but without success.

This is the code I added, for testing purpose, to my library:

Initialization code for RTC use

    // Enable the internal reference clock. MCGIRCLK is active.
    MCG->C1 |= MCG_C1_IRCLKEN_MASK;
    // Select the slow internal reference clock source.
    MCG->C2 &= ~(MCG_C2_IRCS_MASK);
    // Set PTC1 as RTC_CLKIN and select 32 KHz clock source for the RTC module.
    PORTC->PCR[1] &= ~PORT_PCR_MUX_MASK;
    PORTC->PCR[1] = PORT_PCR_MUX(1);    
    SIM->SOPT1 &= ~SIM_SOPT1_OSC32KSEL_MASK;
    SIM->SOPT1 |= SIM_SOPT1_OSC32KSEL(2);
    // Set PTC3 as CLKOUT pin and selects the MCGIRCLK clock to output on the CLKOUT pin.
    SIM->SOPT2 |= SIM_SOPT2_CLKOUTSEL(0x4);
    PORTC->PCR[3] |= (PORT_PCR_MUX(0x5));
    
    // enable RTC clock
    SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;
    RTC->CR = RTC_CR_SWR_MASK;
    RTC->CR &= ~RTC_CR_SWR_MASK;
    
    if (RTC->SR & RTC_SR_TIF_MASK){
         RTC->TSR = 0x00000000;
    }    
    RTC->TCR = RTC_TCR_CIR(1) | RTC_TCR_TCR(0xFF);

    ecc...

But as I said this did not work for me.

I build this class around the rtc api available from mbed. I just added user call back function and the alarm setting.

The demo software use two function to put the MCU in sleep or deepsleep. The MCU will restart for the RTC IRQ.

Revision:
3:2cee0b9ac1ff
Parent:
2:56a50064749e
Child:
4:3bd0dc0c2b2e
--- a/KL25Z_RTC.h	Wed Jun 19 09:03:44 2013 +0000
+++ b/KL25Z_RTC.h	Fri Jun 21 02:22:00 2013 +0000
@@ -60,13 +60,41 @@
 class KL25Z_RTC
 {
 public:
+    /** Constructor.
+     * 
+     * @param   alarm espressed in seconds
+     */
     KL25Z_RTC( unsigned int alarm);
+    
+    /** Start the RTC module
+     * @param none
+     * @return none
+     */
     void RTC_Start( void);
+    
+    /** Start the module. Setting up the IRQ handler for the second IRQ and/or for the Alarm
+     * @param   sec_ptr, alrm_ptr pointer to the IRQ handler
+     * @return none
+     */
     void RTC_Start( void(*sec_ptr)(void), void(*alrm_ptr)(void));
+    
+    /** Return the alarm value
+     * @param   none
+     * #return  the alarm value
+     */
     unsigned int RTC_GetAlarm( void);
+    
+    /** Configure the alarm value
+     * @param   alarm in seconds
+     * @return  none
+     */
     void RTC_SetAlarm( unsigned int alarm);
+    
+    /** Return the second elapsed
+     * @param   none
+     * @return  the second elapsed
+     */
     unsigned int RTC_Read( void);
-    void RTC_Seconds_CallBack( void(*fptr)(void));
     
 private: