This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR5994: How to set up the alarm in RTC module

Part Number: MSP430FR5994

Tool/software: Code Composer Studio

Support Path: /Other topics/Design techniques and how-to guides/How-to guides/

I’m pretty new to the MSP430. For a university project, I need to set up an alarm on specific time of the date. As the user guide suggests there’s a built in RTC module inside the MCU that provide the required features to my application but,

I can’t figure out how to setup the alarm function of it.

I was able to set and run the rtc module.

I tried setting RTAMIN, RTCAHOUR but it didn’t raise the interrupt flag when the time came.

So can you help me to set up the alarm?

Thank you :)

  • Hi Senith,

    Thanks for using MSP decive.

    You could take the code example for RTC_C as reference, which demonstrates the RTC mode by triggering an interrupt every second and minute.

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2015, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     *
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //  MSP430FR5x9x Demo - RTC in real time clock mode
    //
    //  Description: This program demonstrates the RTC mode by triggering an
    //  interrupt every second and minute. This code toggles P1.0 every second.
    //  This code recommends an external LFXT crystal for RTC accuracy.
    //  ACLK = LFXT = 32768Hz, MCLK = SMCLK = default DCO = 1MHz
    //
    //                MSP430FR5994
    //             -----------------
    //        /|\ |              XIN|-
    //         |  |                 | 32768Hz
    //         ---|RST          XOUT|-
    //            |                 |
    //            |            P1.0 |--> Toggles every second
    //            |                 |
    //
    //   William Goh
    //   Texas Instruments Inc.
    //   October 2015
    //   Built with IAR Embedded Workbench V6.30 & Code Composer Studio V6.1
    //******************************************************************************
    
    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop Watchdog Timer
    
        P1DIR |= BIT0;                          // Set P1.0 as output
    
        PJSEL0 = BIT4 | BIT5;                   // Initialize LFXT pins
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Configure LFXT 32kHz crystal
        CSCTL0_H = CSKEY_H;                     // Unlock CS registers
        CSCTL4 &= ~LFXTOFF;                     // Enable LFXT
        do
        {
          CSCTL5 &= ~LFXTOFFG;                  // Clear LFXT fault flag
          SFRIFG1 &= ~OFIFG;
        } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
        CSCTL0_H = 0;                           // Lock CS registers
    
        // Configure RTC_C
        RTCCTL0_H = RTCKEY_H;                   // Unlock RTC
        RTCCTL0_L = RTCTEVIE_L | RTCRDYIE_L;    // enable RTC read ready interrupt
                                                // enable RTC time event interrupt
    
        RTCCTL13 = RTCBCD | RTCHOLD | RTCMODE;  // RTC enable, BCD mode, RTC hold
    
        RTCYEAR = 0x2010;                       // Year = 0x2010
        RTCMON = 0x4;                           // Month = 0x04 = April
        RTCDAY = 0x05;                          // Day = 0x05 = 5th
        RTCDOW = 0x01;                          // Day of week = 0x01 = Monday
        RTCHOUR = 0x10;                         // Hour = 0x10
        RTCMIN = 0x32;                          // Minute = 0x32
        RTCSEC = 0x45;                          // Seconds = 0x45
    
        RTCADOWDAY = 0x2;                       // RTC Day of week alarm = 0x2
        RTCADAY = 0x20;                         // RTC Day Alarm = 0x20
        RTCAHOUR = 0x10;                        // RTC Hour Alarm
        RTCAMIN = 0x23;                         // RTC Minute Alarm
    
        RTCCTL13 &= ~(RTCHOLD);                 // Start RTC
    
        __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 mode w/ interrupts enabled
        __no_operation();
    
        return 0;
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_C_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_C_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(RTCIV, RTCIV__RT1PSIFG))
        {
            case RTCIV__NONE:      break;       // No interrupts
            case RTCIV__RTCOFIFG:  break;       // RTCOFIFG
            case RTCIV__RTCRDYIFG:              // RTCRDYIFG
                P1OUT ^= 0x01;                  // Toggles P1.0 every second
                break;
            case RTCIV__RTCTEVIFG:              // RTCEVIFG
                __no_operation();               // Interrupts every minute - SET BREAKPOINT HERE
                break;
            case RTCIV__RTCAIFG:   break;       // RTCAIFG
            case RTCIV__RT0PSIFG:  break;       // RT0PSIFG
            case RTCIV__RT1PSIFG:  break;       // RT1PSIFG
            default: break;
        }
    }

  • Hi Jetim ,

    Yeah I’ve gone through these example codes.. but these don’t explain how to set up the alarm interrupt.

    I tired enabling RTCAIE and the RTCAMIN and RTCAHOUR, but still it didn’t trigger the interrupt at the time I set.

    I’ll post the method I tried.

  • Hi Senith,

    Sorry for misunderstanding your question.

    For the alarm setting, have you set the alarm enable (AE) bit for each of the alarm registers you used?
  • Hi Senith,

    If there is still issue after setting the AE bit, could you please post your code so that I could review if any other issue?

    Looking forward to your feedback.
  • Hi Jetmi,

    Sorry for the late reply,
    I though I would get an email for every reply on this thread but only got an email for the 1st reply I got. So I didn't know there was new replies. My bad.

    the method i tried was this,

    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop Watchdog Timer
    
        P1DIR |= BIT0 + BIT1;                          // Set P1.0 as output
    
        PJSEL0 = BIT4 | BIT5;                   // Initialize LFXT pins
    
        // Disable the GPIO power-on default high-impedance mode to activate
        // previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        // Configure LFXT 32kHz crystal
        CSCTL0_H = CSKEY_H;                     // Unlock CS registers
        CSCTL4 &= ~LFXTOFF;                     // Enable LFXT
        do
        {
          CSCTL5 &= ~LFXTOFFG;                  // Clear LFXT fault flag
          SFRIFG1 &= ~OFIFG;
        } while (SFRIFG1 & OFIFG);              // Test oscillator fault flag
        CSCTL0_H = 0;                           // Lock CS registers
    
        // Configure RTC_C
        RTCCTL0_H = RTCKEY_H;                   // Unlock RTC
        RTCCTL0_L = RTCOFIE | RTCAIE | RTCRDYIE | RTCTEVIE;    // enable RTC read ready interrupt
                                                // enable RTC time event interrupt
    
        RTCCTL13 = RTCBCD | RTCHOLD | RTCMODE;  // RTC enable, BCD mode, RTC hold
    
        RTCYEAR = 0x2010;                       // Year = 0x2010
        RTCMON = 0x4;                           // Month = 0x04 = April
        RTCDAY = 0x05;                          // Day = 0x05 = 5th
        RTCDOW = 0x01;                          // Day of week = 0x01 = Monday
        RTCHOUR = 0x10;                         // Hour = 0x10
        RTCMIN = 0x32;                          // Minute = 0x32
        RTCSEC = 0x45;                          // Seconds = 0x45
    
        //RTCADOWDAY = 0x2;                       // RTC Day of week alarm = 0x2
        //RTCADAY = 0x20;                         // RTC Day Alarm = 0x20
        RTCAHOUR = 0b10001010;                        // RTC Hour Alarm. 1st bit made 1 to enable AE
        RTCAMIN =  0b10100011;                         // RTC Minute Alarm.  Same as above
    
        RTCCTL13 &= ~(RTCHOLD);                 // Start RTC
    
        __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3 mode w/ interrupts enabled
        __no_operation();
    
        return 0;
    }
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_C_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_C_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(RTCIV, RTCIV__RT1PSIFG))
        {
            case RTCIV__NONE:      break;       // No interrupts
            case RTCIV__RTCOFIFG:  break;       // RTCOFIFG
            case RTCIV__RTCRDYIFG:              // RTCRDYIFG
                P1OUT ^= 0x01;                  // Toggles P1.0 every second
                break;
            case RTCIV__RTCTEVIFG:              // RTCEVIFG
               // __no_operation();              // Interrupts every minute - SET BREAKPOINT HERE
                break;
            case RTCIV__RTCAIFG:
                P1OUT = 0x02;                   //Turn on p1.2 LED when alarm is triggered
                break;                           // RTCAIFG
            case RTCIV__RT0PSIFG:  break;       // RT0PSIFG
            case RTCIV__RT1PSIFG:  break;       // RT1PSIFG
            default: break;
        }
    }
    

    The above code is one of the sample codes provided. I then modified it to include the alarm function. Am I enabling the AE on wrong?

    Thank you.

  • Hi Senith,

    It seems the AE bits are set properly. I will test your code on my board and let your know further result.
  • Hi Wei,

    Sure thing...

    Thank you

  • Hi Senith,

    I tried your code but it work from my side with the RTCMIN value modified.

    In your code, you set the alarm for every MIN of 23, but the initialed time is MIN of 32, which means you need to wait 51 min for the alarm after running the code. I just set the initialed time to MIN 22 SEC 55 and then it could run into the case RTCIV__RTCAIFG: of the RTC_ISR.
    RTCMIN = 0x22; // Minute = 0x22
    RTCSEC = 0x55; // Seconds = 0x55

**Attention** This is a public forum