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.
Tool/software: Code Composer Studio
Hello,
I'm trying to use the RTC counter of the MSP430FR235 on a Launchpad Devboard to keep track of time in LPM3 (or LPM3.5 for that matter). However, after about 17 minutes (1021 seconds), the register values seem to get corrupted. I've tried a lot already, but I can't see a solution because I have absolutely no idea what could have caused this error.
#include <msp430.h> #include <stdint.h> //#pragma LOCATION(rtcState, 0x660); //Backup memory remains powered during LPM3.5 //volatile struct Time { // uint8_t seconds; // uint8_t minutes; // uint8_t hours; //} rtcState; uint8_t seconds; uint8_t minutes; uint8_t hours; int cnt; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P2SEL1 |= BIT6 | BIT7; // P2.6~P2.7: crystal pins CSCTL4 = SELMS__DCOCLKDIV | SELA__XT1CLK; // MCLK=SMCLK=DCO; ACLK=XT1 // Port Configuration all un-used pins to output low P1OUT = 0x00; P2OUT = 0x00; P3OUT = 0x00; P4OUT = 0x00; P5OUT = 0x00; P6OUT = 0x00; P1DIR = 0xff; P2DIR = 0xff; P3DIR = 0xff; P4DIR = 0xff; P5DIR = 0xff; P6DIR = 0xff; // Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings PM5CTL0 &= ~LOCKLPM5; do { CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag SFRIFG1 &= ~OFIFG; }while (SFRIFG1 & OFIFG); // Test oscillator fault flag // 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; if (SYSRSTIV == SYSRSTIV_LPM5WU) // When woken up from LPM3.5, reinit { // If MCU wakes up from LPM3.5, re-init and then return to LPM3.5 again. __no_operation(); // For debug } else { // Device powered up from a cold start. __no_operation(); // For debug } //This is for LPM3.5 //PMMCTL0_H = PMMPW_H; // Open PMM Registers for write //PMMCTL0_L |= PMMREGOFF; // and set PMMREGOFF seconds=0; minutes=0; hours=0; cnt=0; __bis_SR_register(LPM3_bits | GIE); // Enter LPM3, enable interrupt __no_operation(); // For debug } // 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 if(cnt>1019) { __no_operation(); // For debug } if(seconds > 60) { __no_operation(); // For debug } cnt++; seconds++; P1OUT ^= BIT0; if(seconds >= 60) { seconds = 0; P1OUT ^= BIT0; minutes++; if(minutes >= 60) { P1OUT ^= BIT0; minutes = 0; hours++; if(hours >= 24) { hours = 0; P1OUT ^= BIT0; } } } break; default: break; } __bis_SR_register(LPM3_bits | GIE); // Enter LPM3, enable interrupt __no_operation(); // For debug }
When cnt=1020 everything is fine. If I then debug into (F5), the next RTC interrupt shows that the variable seconds is set to 220, which should be impossible. Do you see a mistake in my code?
Best regards,
Samot
> __bis_SR_register(LPM3_bits | GIE);
Don't go into LPM in an ISR. Each successive interrupt will grow the stack, until it eventually overflows.
Just "return" from the ISR, which will put you back into LPM. [Ref User Guide (SLAU445I) Sec 1.3.4.2]
Hi Thomas,
I haven’t heard from you for a couple of days now, so I’m assuming you were able to resolve your issue.
If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information.
If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.
Hi Dennis,
Thank you very much for your fast response. The issue is resolved. I knew it shouldn't be difficult, but it's hard to find such details if you don't know where to look sometimes. Thanks again!
Best regards
**Attention** This is a public forum