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.

MSP432 RTC example

hy guys I start work with the RTC module and therefore I tested the code of the TI side (see below).

//******************************************************************************
//  MSP432P401 Demo - RTC in real time clock mode
//
//  Description: This program demonstrates the RTC mode by triggering the event
//  interrupt RTCRDYIE event, which triggers every minute change. P1.1 toggles
//  every minute to indicate this interrupt.
//  After configuring the RTC, device goes into LPM3 and waits for the RTC interrupts.
//  Notice that RTC starting second is set to be 45, so after starting the program
//  the first RTC interrupt should trigger after ~15 seconds. Consequent interrupts
//  should occur every minute.
//  This code recommends an external LFXT1 crystal for RTC accuracy.
//  ACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO = 32 x ACLK = 1048576Hz
//
//                MSP432p401rpz
//             -----------------
//        /|\ |              XIN|-
//         |  |                 | 32kHz
//         ---|RST          XOUT|-
//            |                 |
//            |            P1.0 |--> Toggles every minute
//            |                 |
//
//
//   Dung Dang
//   Texas Instruments Inc.
//   November 2013
//   Built with Code Composer Studio V6.0
//******************************************************************************
#include "msp.h"

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;               // Stop WDT

    /* Configure P1.0 LED */
    P1DIR |= BIT0 ;
    P1OUT &= ~( BIT0 );


    // Configure RTC
    RTCCTL0_H = RTCKEY_H ;                 // Unlock RTC key protected registers
    RTCCTL0_L |= RTCTEVIE ;
    RTCCTL0_L &= ~(RTCTEVIFG);
    RTCCTL1 = RTCBCD | RTCHOLD ;
    // RTC enable, BCD mode, RTC hold
    // enable RTC read ready interrupt
    // enable RTC time event interrupt

    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

    RTCCTL1 &= ~(RTCHOLD);                    // Start RTC calendar mode

    RTCCTL0_H = 0;                            // Lock the RTC registers


    /* Enable all SRAM bank retentions prior to going to LPM3 (Deep-sleep) */
    SYSCTL_SRAM_BANKRET |= SYSCTL_SRAM_BANKRET_BNK7_RET;

    __enable_interrupt();
    NVIC_ISER0 = 1 << ((INT_RTC_C - 16) & 31);


    SCB_SCR |= SCB_SCR_SLEEPONEXIT;        // Sleep on exit from ISR

      while (1)
      {

          /* Setting the sleep deep bit */
          SCB_SCR |= (SCB_SCR_SLEEPDEEP);

          __sleep();


          /* Clearing the sleep deep bit */
          SCB_SCR &= ~(SCB_SCR_SLEEPDEEP);

      }

}

// RTC interrupt service routine

void RtcIsrHandler(void)
{

    if (RTCCTL0 & RTCTEVIFG)
    {
        P1OUT ^= BIT0;
        RTCCTL0_H = RTCKEY_H ;
        RTCCTL0_L &= ~RTCTEVIFG;
        RTCCTL0_H = 0;
    }

}

All works great, but I don't understand how the interrupt got called every minute when the RTCAMIN register was set to 0x23 (23) and not 1. 

Maybe anyone can help me ?        

  • Hi Christoph,

    I believe it is because of the real time clock time event in RTCCTL1 by default it is set to "minute changed". And this interrupt is being enabled by RTCCTL0_L |= RTCTEVIE ;

    Regards,

    David
  • Hi David,

    I share your opinion but the thing which is really strange, is the value of the RTCAMIN register. The value was set to 0x23 and not to 1, this means that the interrupt would be called every 23 minutes and not every minute as wanted. But on the other hand the programm ran and the interrupt got called every minute. But I don't know why?

  • Hi Christoph,

    Christoph Marko said:
    share your opinion but the thing which is really strange, is the value of the RTCAMIN register. The value was set to 0x23 and not to 1, this means that the interrupt would be called every 23 minutes and not every minute as wanted

    The example code needs to be updated, because we are setting an alarm that is not used, in other words RTCAMIN is set to 0x23 but it is not being used at all.

    Christoph Marko said:
    But on the other hand the programm ran and the interrupt got called every minute. But I don't know why?

    As I mentioned before this example code is enabling the RTC time event interrupt and it is also setting the RTCTEV for 1 minute alarm.

     Hopefully this helps.

       Regards,

       David

  • Hi Daivid,

    Thank you for explaination, but I have an additional question.

    How do I set an interrupt for only every minute?

    Could I assign the value 1 to the RTCAMIN register?

    Christoph,

  • If there isn't problem i would be interested to answer because i need the same information. Furthermore is there possiblity to set an interrupt every second and not every minute? thanks

**Attention** This is a public forum