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.

MSP430FR6989: Shared vector ISR

Part Number: MSP430FR6989

I'm trying to achieve the following:

I want to flash an LED when the TAR rolls back to zero event happens, and also i want to flash the red LED when channel 1's compare event occurs.

Channel 1 and TAR share the same vector TIMER_A1_VECTOR, thus we would only need one ISR. Is this statement correct?

My implementation:

#include <msp430.h> 
#define redLED BIT0 // Red at P1.0
#define greenLED BIT7 // Green at P9.7

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD; // Stop WDT
    PM5CTL0 &= ~LOCKLPM5; // Enable GPIO pins
    P1DIR |= redLED;
    P9DIR |= greenLED;
    P1OUT &= ~redLED;
    P9OUT &= ~greenLED;

    TA0CCR1 = (12000 - 1);
    TA0CCTL1 &= ~CCIFG;
    TA0CCTL1 |= CCIE;

    TA0CTL = TASSEL_1 | ID_0 | MC_2 | TACLR;

    while (1) {}

	return 0;
}

#pragma vector = TIMER0_A1_VECTOR
__interrupt void T0A1_ISR()
{
    if ((TA0CTL & TAIFG) != 0){
        P1OUT ^= greenLED;
        TA0CTL &= ~TAIFG;
    }

    if ((TA0CCTL1 & CCIFG) != 0){
        P1OUT ^= redLED;
        TA0CCR1 += 12000;
        TA0CCTL1 &= ~CCIFG;
    }
}

// Configures ACLK to 32 KHz crystal
void config_ACLK_to_32KHz_crystal() {

    // By default, ACLK runs on LFMODCLK at 5MHz/128 = 39 KHz
    // Reroute pins to LFXIN/LFXOUT functionality
    PJSEL1 &= ~BIT4;
    PJSEL0 |= BIT4;
    // Wait until the oscillator fault flags remain cleared
    CSCTL0 = CSKEY; // Unlock CS registers

    do {

        CSCTL5 &= ~LFXTOFFG; // Local fault flag
        SFRIFG1 &= ~OFIFG; // Global fault flag

    } while((CSCTL5 & LFXTOFFG) != 0);

    CSCTL0_H = 0; // Lock CS registers
return;
}

  • Yes.

    The "A0" vector is for CCR0 only. You don't need to check (indeed you can't check) nor clear.

    The "A1" vector is for all-the-others. You need to check and clear, just as you have done.

  • So, am not sure I understood what you meant. 

    If register TAxCCTL1 shares vector A1 with register TACTL. I only need one interrupt service routine, however, I would have to check both of these register's flag bit to see if one of them was triggered. This is what am trying to accomplish here. Though it makes sense to me, and it compiles! There's still no response. Why would this be the case?

  • 1) You need to enable interrupts globally. Add this just before your while() loop:

    > __enable_interrupt();  // GIE=1

    2) Typo alert:

    >        P1OUT ^= greenLED;

    Try: 

    >        P9OUT ^= greenLED;

     

  • AH! I was overthinking the problem. This is my fault for not double checking my code.

    It works! Thank you Bruce. 

  • Hi,

    Can you tell me,

    how you are using the Aclk ?

     You have used the function for Aclk ,

    But I do not find the use of that function in Main() ?

    And how you are calling the interrupt in main function?

    As stated above, please use GIE.

**Attention** This is a public forum