Hello,
I wrote a small piece of code in CCS compiler with MSP430FR4133 Launch pad. The code has to update HRS,MINS & SEC global variables.
It has to blink LED at P1.0 for every second which is written in the interrupt service routine & LED at P4.0 should blink every 2 seconds in the main loop.
The problem is that P1.0 blinks but P4.0 never blinks it just stays on, which means that P4.0 is set HIGH but assoon as that happens RTC Vector is triggered.
after that it never heads to main loop().
Can anyone tell me how to implement this , preferrably with a code example or some sorts.
#include <msp430.h> unsigned int HRS; unsigned int MINS; unsigned int SEC; int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P4SEL0 |= BIT1 | BIT2; // set XT1 pin as second function do { CSCTL7 &= ~(XT1OFFG | DCOFFG); // Clear XT1 and DCO fault flag SFRIFG1 &= ~OFIFG; }while (SFRIFG1 & OFIFG); // Test oscillator fault flag P1OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state P1DIR |= BIT0; // Set P1.0 to output direction P4OUT &= ~BIT0; // Clear P1.0 output latch for a defined power-on state P4DIR |= BIT0; // Set P1.0 to output direction PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode // to activate previously configured port settings // Initialize RTC // Source = 32kHz crystal, divided by 1024 RTCCTL = RTCSS__XT1CLK | RTCSR | RTCPS__1024 | RTCIE; // RTC count re-load compare value at 32. // 1024/32768 * 32 = 1 sec. RTCMOD = 32-1; __bis_SR_register(GIE); // Enter LPM3, enable interrupt while(1) { if(MINS%2==0) { P4OUT |=BIT0; _delay_cycles(1000000); P4OUT &=~BIT0; } } } // RTC interrupt service routine #pragma vector=RTC_VECTOR __interrupt void RTC_ISR(void) { if(RTCIV & RTCIV_RTCIF) { // RTC Overflow P1OUT ^= BIT0; SEC++; if(SEC==60) { MINS++; SEC=0; } if(MINS==60) { HRS++; MINS=0; } if(HRS==24) { HRS=0; } } }