Part Number: MSP430FR2311
Other Parts Discussed in Thread: MSP430FR4133,
Tool/software: Code Composer Studio
I am trying to use VLOCLK as clock source for the RTC module in LPM3 and use RTC interrupt to blink an LED every one second. My ultimate aim is to use RTC in LPM3.5 without any external oscillators.
Here's my code:
#include <msp430.h>
#define VLOCLK
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
#ifndef VLOCLK
P2SEL1 |= BIT6 | BIT7; // P2.6~P2.7: crystal pins
do
{
CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1 & OFIFG); // Test oscillator fault flag
#else
// Selecting VLO as Main Osc: Refer 3.2.2 in www.ti.com/.../slau445g.pdf
CSCTL4 |= SELMS__VLOCLK ;
CSCTL5 &= ~VLOAUTOOFF;
CSCTL5 |= DIVM__1;
#endif
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
#ifndef VLOCLK
// RTC count re-load compare value at 32.
// 1024/32768 * 32 = 1 sec.
RTCMOD = 32-1;
// Initialize RTC
// Source = 32kHz crystal, divided by 1024
RTCCTL = RTCSS__XT1CLK | RTCSR | RTCPS__1024 | RTCIE;
#else
// VLOCLK frequency is 10KHz.
// 1000/10000 * 10 = 1 sec
RTCMOD = 10-1;
RTCCTL |= RTCSS__VLOCLK | RTCPS__1000 | RTCIE | RTCSR;
#endif
__bis_SR_register(LPM3_bits | GIE); // Enter LPM3, enable interrupt
//while(1);
}
// 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;
}
}
The LED toggles every 1.516 Seconds instead of every 1 Seconds.
Here's the screenshot of the logic analyzer connected to P1.0:
How to configure the RTC clock correctly?
EDIT:
The same code when programmed on MSP430FR4133 Launchpad, the LED toggles at 1.135 Second (Still not close to 1 second).
Attached the logic analyzer screenshot:

