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

Hi! I am trying to setup the RTC_C module. I used other examples for the actual setup and I think it is about right, but I cannot get the RTCIV_RTCAIFG (alarm interrupt) interrupt to fire. RTCIV_RTCTEVIFG and RTCIV_RTCRDYIFG interrupts are working so I think it has something to only do with the alarm setup. Any help or suggestions would be appreciated! Thank you!

Here's what I have done:

unsigned int PollingInterval = 1;

int main(void){

// **RTC_C SETUP**

RTCCTL0_H = RTCKEY_H; //Unlock RTC Registers

RTCCTL0_L = RTCTEVIE_L | RTCRDYIE_L; //Enable RTC Read Ready Interrupt and Time Event Interrupt

RTCCTL13 = RTCBCD | RTCMODE | RTCHOLD; //Enable BCD mode, enable RTC in calendar mode, hold RTC while date/time values are set

//Set date and time information

RTCYEAR = 0x2018;

RTCMON = 0x7;

RTCDAY = 0x25;

RTCDOW = 0x4;

RTCHOUR = 0x12;

RTCMIN = 0x50;

RTCSEC = 0x00;

//RTC ALARM SETUP

unsigned int Temp_time = 0;

Temp_time = (((RTCMIN >> 4) & 0x0F) * 10) + (RTCMIN & 0x0F);

Temp_time += PollingInterval;

if(Temp_time > 59){

Temp_time -=60;

RTCAMIN = (Temperary_time / 10) << 4;

RTCAMIN |= (Temperary_time % 10);

}else{

RTCAMIN = (Temp_time/10) << 4;

RTCAMIN |= (Temp_time%10);

}

RTCAMIN |= RTCAE; //enable minute alarm

RTCCTL13 &= ~(RTCHOLD); // Start RTC

RTCCTL0_H = 0; //Lock RTC Registers

}

#pragma vector = RTC_C_VECTOR

__interrupt void RTC_C_ISR(void){

switch(__even_in_range(RTCIV, RTCIV__RT1PSIFG)){

    case RTCIV_RTCTEVIFG:           // minute interrupt

        break;

        case RTCIV_RTCRDYIFG:           //second interrupt

            break;

        case RTCIV_RTCAIFG:             // can give an interrupt every hour at a specific minute;

            MEAS_RTC_RATE(PollingInterval);

            break;

default:

        break;

      }

  }

edit: tried to fix formatting

  • Hi Joshi,
    We are looking into your post. Will keep you update.

    Best regards,
    Cash Hao
  • Hi Joshi,

    Have you read this part in the USer's guide page 690?

    Best regards,

    Cash Hao

  • Hi Cash Hao,

    Yes, that helped me set it up, as the code shows, since I am setting the RTCAMIN and and the AE bit for it. I tried clearing it all, but the interrupts are still not happening.

    Sanskriti

  • Hi Sanskriti,
    I don't see in your code that you cleared up all the other AE bits. Can you debug on your code? Just set a breakpoint before 'RTCCTL0_H = 0;' and check the registers.

    Best regards,
    Cash Hao
  • Hi Cash Hao,

    Yes, I added that after I read the snippet you shared the first time so it's not in the code I posted. Yes, I debugged by looking at the registers and they all were all as expected.

    Thanks,

    Sanskriti

  • Hi Sanskriti,

    If it still doesn't work, you can send out your current code.

    Best regards,

    Cash Hao

  • I have included the code below. Thank you for your help! The while loop + counter is to prevent the code from ending
    /*
     * mainTest.c
     *
     *  Created on: Jul 31, 2018
     *      Author: Sanskriti
     */
    #include <msp430fr5994.h>
    int PollingInterval = 2;
    volatile int counter = 0;
    int main(void){
        MCU_Init();
        MCU_Init_Clock();
        RTCsetup();
        while(1){
            if(counter < 5){
                counter += 2;
            }else{
                counter +=1;
            }
        }
    }
    void MCU_Init()
    {
        // configure MCU Pins
        WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer
        PM5CTL0 &= ~LOCKLPM5;       //disable the GPIO power-on default high-impedance
    }
    void MCU_Init_Clock()
    {
          PJSEL0 = BIT4 | BIT5;               //initialize the LFXT pins
          CSCTL0_H = CSKEY >> 8;                                // Unlock CS registers
          CSCTL0 = CSKEY;
          CSCTL1 = DCOFSEL_0;                                   // Set DCO = 1MHz (measured with Oscilloscope to be slightly less that 1 MHz)
          CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK;  // set ACLK=VLO;SMCLK=DCO Note: the VLO is typically 10 kHz (measured with Oscilloscope to be slightly less that 10 MHz)
          CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1;                 // set all dividers
          //start of code added for RTC
          CSCTL4 &= ~LFXTOFF;                                       //enable the crystal
          do{
              CSCTL5 &= ~LFXTOFFG;                                  //clear LFXT  fault flag
              SFRIFG1 &= ~OFIFG;
          }while (SFRIFG1 & OFIFG);                                 //test oscillator fault flag
          //end of code added for real time clock
          CSCTL0_H = 0;                                         // Lock CS Registers
    }
    void RTCsetup(void){
        //RTC_C setup
        RTCCTL0_H = RTCKEY_H; // unlock RTC registers
        RTCCTL0_L = RTCTEVIE_L | RTCRDYIE_L; //Enable RTC Ready Interrupt and Time Event Interrupt
        RTCCTL13 = RTCBCD | RTCMODE | RTCHOLD; // Enable BCD mode, enable RTC in calendar mode, hold while date/time values are set
        //SET date time info
        RTCYEAR = 0x2018;
        RTCMON = 0x7;
        RTCDAY = 0x25;
        RTCDOW = 0x4;
        RTCHOUR = 0x12;
        RTCMIN = 0x50;
        RTCSEC = 0x00;
        //RTC clock alarm setup
        RTCalarmSet(PollingInterval);
        RTCAMIN |= RTCAE; //enable minute alarm
        RTCCTL13 &= ~(RTCHOLD); //start RTC
        RTCCTL0_H = 0;
    }
    void RTCalarmSet(int PollingInterval){
        RTCAMIN = 0x00;
        RTCAHOUR = 0x00;
        RTCADOW = 0x00;
        RTCADAY =0x00;
        unsigned int Temp_time = 0;
        Temp_time = (((RTCMIN >> 4) & 0x0F) * 10) + (RTCMIN & 0x0F);
        Temp_time += PollingInterval;
        if(Temp_time > 59){
            Temp_time -= 60;
            RTCAMIN = (Temp_time / 10) << 4;
            RTCAMIN |= (Temp_time % 10);
        }else{
            RTCAMIN = (Temp_time / 10) << 4;
            RTCAMIN |= (Temp_time % 10);
        }
    }
    #pragma vector = RTC_C_VECTOR
    __interrupt void RTC_C_ISR(void){
        switch(__even_in_range(RTCIV, RTCIV__RT1PSIFG)){
        case RTCIV_RTCTEVIFG:   //minuteInterrupt
            counter = counter - 1;
            break;
        case RTCIV_RTCRDYIFG:   //secondInterrupt
            break;
        case RTCIV_RTCAIFG:     //alarm interrupt
            RTCalarmSet(PollingInterval);
            RTCAMIN |= RTCAE; //enable minute alarm
            counter = 0;
            break;
        default:
            break;
        }
    }
  • Is there any other information I can provide? I am still puzzled as to why only the alarm interrupt is not working

  • HI Sanskriti,
    I got the same results, the alarm interrupt can not be triggered. I am asking more knowledgeable engineer to look into this issue. We can discuss through email. My email is cash-hao@ti.com. Thanks!

    Best regards,
    Cash Hao

**Attention** This is a public forum