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.

MSP430FR2311: RTC Interval Incorrect

Part Number: MSP430FR2311

I'm not sure what is going on if it is my mistake or an issue with driverlib, but I cannot get the expected interrupt rate from the RTC.  The code below gives me an interrupt period of 2ms.  If I do the math 1/.002 = 500hz.  500hz *32000 = 16MHz.  It seems like the clock to the RTC module isn't correct.

I also get a warning on     RTC_clearInterrupt(RTC_BASE, RTC_CLOCKSOURCE_SMCLK);   that says "#70-D integer conversion resulted in truncation"

*EDIT:  As another datapoint I have a TimerB configured to interrupt at 128Hz with ACLK connected as its CLK source.  I verified that it is running at 128Hz as expected.

int main(void) {
    //Stop WDT
    WDT_A_hold(WDT_A_BASE);

    initClockTo16MHz();

/* Initialize peripherals */
    initGPIO();
    initRTC();

while(1)
{

}
}


void initGPIO(void){

    // INPUT IS 0, OUTPUT is 1

    //Set Px.x to output direction
    P1DIR |= 0b00000000;  // inputs
    P2DIR |= 0b00001011;
    P2OUT = 0x00;

    PMM_enableTempSensor();  // enable temperature sensor
    PMM_enableInternalReference();

     // Select P2.0 as PWM Timer output function
    P2SEL0 |= GPIO_PIN0;

    P1SEL1 &= ~(BIT7);                 // USCI_A0 UART operation TX only
    P1SEL0 |= BIT7;

    // I2C pins
    P1SEL0 |= BIT2 | BIT3;
    P1SEL1 &= ~(BIT2 | BIT3);

    //ADC Pins
    P1SEL0 |= BIT0 | BIT1;
    P1SEL1 |= BIT0 | BIT1;
    /*
     * Disable the GPIO power-on default high-impedance mode to activate
     * previously configured port settings
     */
    PMM_unlockLPM5();
}

void initClockTo16MHz()
{
    // Configure one FRAM waitstate as required by the device datasheet for MCLK
    // operation beyond 8MHz _before_ configuring the clock system.
    FRCTL0 = FRCTLPW | NWAITS_1;

    __bis_SR_register(SCG0);    // disable FLL
    CSCTL3 |= SELREF__REFOCLK;  // Set REFO as FLL reference source
    CSCTL0 = 0;                 // clear DCO and MOD registers
    CSCTL1 &= ~(DCORSEL_7);     // Clear DCO frequency select bits first
    CSCTL1 |= DCORSEL_5;        // Set DCO = 16MHz
    CSCTL2 = FLLD_0 + 487;      // set to fDCOCLKDIV = (FLLN + 1)*(fFLLREFCLK/n)
                                //                   = (487 + 1)*(32.768 kHz/1)
                                //                   = 16 MHz

    __delay_cycles(3);
    __bic_SR_register(SCG0);                        // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1));      // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;
}


// RTC interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=RTC_VECTOR
__interrupt void RTC_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
#else
#error Compiler not supported!
#endif
{

   switch(__even_in_range(RTCIV,RTCIV_RTCIF))

   {

       case  RTCIV_NONE:   break;          // No interrupt

       case  RTCIV_RTCIF:                  // RTC Overflow
           P2OUT ^= BIT3;
           //P2OUT &= ~BIT3;
           //P2OUT |= BIT3;
           break;

       default: break;

   }

}

void initRTC()
{
    SYSCFG2 |= RTCCKSEL;  // CONFIGURE TO USE ACLK INSTEAD OF SMCLK

    RTC_init(RTC_BASE, 32000, RTC_CLOCKPREDIVIDER_1);
    RTC_clearInterrupt(RTC_BASE, RTC_CLOCKSOURCE_SMCLK);
    RTC_enableInterrupt(RTC_BASE, RTC_OVERFLOW_INTERRUPT);
    RTC_start(RTC_BASE, RTC_CLOCKSOURCE_SMCLK);
}

  • Hi,

    SYSCFG2 |= RTCCKSEL;  // CONFIGURE TO USE ACLK INSTEAD OF SMCLK

    What clock source are you using for RTC, ACLK or SMCLK?

    Regards,

    Ling

  • I believe that line of code tells it to use ACLK instead of SMCLK. I'm assuming this based on Figure 6-1 www.ti.com/.../msp430fr2311.pdf So by the figure I'm assuming with SYSCFG2 RTCCKSEL set, it overrides to use ACLK where I tell it to use SMCLK in the initRTC() function
  • Please refer to example code:

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2014, 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 COPYRRTCCTLIGHT 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--*/
    //******************************************************************************
    //  MSP430FR231x Demo - RTC, toggle P1.0 every 1s
    //
    //  Description: Configure ACLK to use REFO as RTC source clock,
    //               ACLK = REFO = 32kHz, MCLK = SMCLK = default DCODIV = ~1MHz.
    //
    //           MSP430FR2311
    //         ---------------
    //     /|\|               |
    //      | |               |
    //      --|RST            |
    //        |               |
    //        |               |
    //        |          P1.0 |---> LED
    //        |               |
    //
    //   Darren Lu
    //   Texas Instruments Inc.
    //   Oct. 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
    
        P1OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
        P1DIR |= BIT0;                          // Set P1.0 to output direction
    
        PM5CTL0 &= ~LOCKLPM5;                   // Disable the GPIO power-on default high-impedance mode
                                                // to activate previously configured port settings
    
    
        // RTC count re-load compare value at 32.
        // 1024/32768 * 32 = 1 sec.
        RTCMOD = 32-1;
                                                // Initialize RTC
        // Source = ACLK = REFO, divided by 1024
        SYSCFG2 |= RTCCKSEL;                    // Select ACLK as RTC clock
        RTCCTL = RTCSS_1 | RTCSR | RTCPS__1024 | RTCIE;
    
        __bis_SR_register(LPM3_bits | GIE);     // Enter LPM3, enable interrupt
    }
    
    // RTC interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=RTC_VECTOR
    __interrupt void RTC_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(RTC_VECTOR))) RTC_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        switch(__even_in_range(RTCIV,RTCIV_RTCIF))
        {
            case  RTCIV_NONE:   break;          // No interrupt
            case  RTCIV_RTCIF:                  // RTC Overflow
                P1OUT ^= BIT0;
                break;
            default: break;
        }
    }
    

  • I will try that. It appears in my code I am doing the exact same thing.

**Attention** This is a public forum