Hi folks. I'm fairly new to MSP430 development, though I've tinkered with AVRs for many years previously. Currently I'm working on a board that needs to use the onboard RTC_C module on the MSP430F6726 (using the Rowley CrossWorks/CrossStudio IDE). I've read through the user guide's RTC_C section thoroughly and written many variations of the setup code, including copying and pasting the official example (MSP430F673X_RTC_01.c)... I can't get it to count or fire RTCRDY interrupts no matter what I do. Below is my simple test code, which should toggle an LED on P5.2 every second (but doesn't work). Note that I have a 32.768 KHz watch crystal on XT1.
#include <__cross_studio_io.h>
#include <msp430.h>
#include <inmsp.h>
// initialize main clock sources
// MCLK = 19.6608 MHz (about the max speed I can get without tweaking other chip settings)
// SMCLK = 4.9152 MHz
// ACLK = 32.768 KHz
void SetupClock(void)
{
UCSCTL3 = 0; // FLL uses XT1CLK (default)
UCSCTL4 = 0+ // ACLK = XT1CLK = 32.768 KHz
SELS1+SELS0+ // SMCLK = DCOCLK
SELM1+SELM0; // MCLK = DCOCLK
UCSCTL5 = DIVS1; // SMCLK = DCOCLK/4
UCSCTL6 = XT2OFF | XCAP0 | XCAP1; // turn off XT2, 12pF load capacitance on XT1
_BIS_SR(SCG0); // disable the FLL control loop
//__bis_SR_register(SCG0); // (alternate way of disabling FLL control loop)
UCSCTL0 = 0; // setup for 13 MHz
UCSCTL1 = DCORSEL_5;
UCSCTL2 = 599; // FLL multiplier; DCOCLK = (599+1)*REFOCLK = 19.6608 MHz
_BIC_SR(SCG0); // enable the FLL control loop
__delay_cycles(250000); // wait for DCO to settle
// Loop until XT1, XT2 & DCO fault flag is cleared
do
{
UCSCTL7 &= ~(XT2OFFG | XT1LFOFFG | DCOFFG);
// Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG; // Clear fault flags
} while (SFRIFG1 & OFIFG); // Test oscillator fault flag
}
void RTCISR(void) __interrupt[RTC_VECTOR]
{
unsigned int rtcivBackup;
rtcivBackup = RTCIV;
//RTC ready
if (rtcivBackup == RTCIV_RTCRDYIFG)
{
//toggle LED
P5OUT ^= BIT2;
}
}
void SetupRTC(void)
{
//unlock the rtc registers
RTCCTL0_H = RTCKEY_H;
//enable the rtc ready interrupt
RTCCTL0_L = RTCRDYIE_L;
//setup the calendar registers
RTCYEAR = 2013;
RTCMON = 7;
RTCDAY = 24;
RTCDOW = 3;
RTCHOUR = 13;
RTCMIN = 45;
RTCSEC = 0;
//clear the prescale counters
RT0PS = 0;
RT1PS = 0;
//calendar mode
RTCCTL13_L |= RTCMODE_L;
//unhold the rtc
RTCCTL13_L &= ~RTCHOLD_L;
//lock the RTC registers again
RTCCTL0_H = 0;
}
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
SetupClock();
//setup output LED
P5DIR |= BIT2;
//start with LED off
P5OUT |= BIT2;
SetupRTC();
//enable general interrupts
_BIS_SR(GIE);
while(1) {}
return 0;
}
Any suggestions on how I can make it work? The code should also work with CCS if you change the RTCISR function definition. Thanks for the help, I'm really stuck on this problem.