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.

Compiler/MSP430G2553: Problem with interrupts

Part Number: MSP430G2553


Tool/software: TI C/C++ Compiler

Hello everyone,

I have MSP430G2553 LaunchPad and I have problem with interrupts.

I wanted to write simple program which would blink leds with ~12,5Hz frequency, and with button, which would enable/disable blinking. Both features would use interrupts. I wrote simple code, but it goes forever after entering TIMER0_A1_VECTOR. Could you help me? Thanks in advance, there is the code:

#include <msp430g2553.h>


void main(void)
{
    WDTCTL = WDTPW + WDTHOLD; 			// Stop watchdog timer
    P1DIR |= BIT0 + BIT6;			// P1.1 + P1.6 diodes
    P1DIR &= ~BIT3;				// P1.3 switch
    P1OUT |= BIT0 + BIT6; 			// diodes on

    P1REN |= BIT3;				// resistor on P1.3
    P1OUT |= BIT3;				// pull up

    P1IE |= BIT3; 				// P1.3 interrupt enable
    P1IES |= BIT3; 				// high to low edge
    P1IFG &= ~BIT3; 				// interrupt flag clear

    //TIMER A
    TACTL = TASSEL_2 + MC_1 + ID_3 + TAIE;	// TAIE activates interrupts, TASSEL_2 SMCLK - 1MHz, MC_1 UP mode, ID_3 1MHz/8 = 125kHz

    //TIMER 0
    TA0CCR0 = 50000;				// 125kHz / 50000 = 2.5Hz -> 400ms
    TA0CCTL0 = CCIE;				// TA0CCR0 interrupt activated

    _BIS_SR(LPM0_bits + GIE); 			// enters LPM0 with interrupt enable

}


#pragma vector=TIMER0_A0_VECTOR			// timer interrupt
__interrupt void Timer_A (void)

{
  P1OUT ^= BIT0 + BIT6;				// toggle diodes
}


#pragma vector=TIMER0_A1_VECTOR			// timer interrupt
__interrupt void Timer_AA (void)

{
  P1OUT ^= BIT0 + BIT6;				// toggle diodes
}


#pragma vector=PORT1_VECTOR			// switch interrupt
__interrupt void Port_1(void)
{
    CCTL0 ^= CCIE;				// toggle CCTL0 interrupt enabled
    P1OUT ^= BIT0 + BIT6;
    P1IFG &= ~BIT3; 				// interrupt flag clear
}

  • The first interrupt can be raised only by CCR0, so executing that interrupt automatically clears the interrupt flag bit.

    The second interrupt has many possible sources. Your code has to clear the interrupt flag bits for the sources that it has actually handled. Alternatively, use the TA0IV register to check for the interrupt source; reading it automatically clears the flag for the source that it returns.

  • Thank you for response, Clemens!

    I tried to add
    TA1CCTL0 &= ~CCIFG;
    after 42 line, but it doesn't work.
    I thought that interrupts caused by interial devices (such as timers) cleans flags automatically.
  • Only a few interrupts clear their flags automatically. You also set TAIE, so TAIFG might be the bit that keeps the ISR active. Why do you have two timer interrupts at the same time? I think TAIE is not necessary here. And keep in mind that the input button bounces and will generate multiple interrupts.

  • I deleted TAIE and it works perfectly now. Thank you very much! :)
    I thought that TAIE is necessary to activate different timer interrupts. Thanks again! :)

**Attention** This is a public forum