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.

MSP430F169 - TAIFG Interrupt not working

Other Parts Discussed in Thread: MSP430F169

MCU: MSP430F169
ACLK: 32768 Hz

I am trying to use the TimerA module to create interrupts every 1 second. I have the following code but it does not seem to work the way I expect. I set the Timer on continueos mode and set TAR = 0xFFFF - 512. I should get a 1 second interrupt every 512 clock cycles.

Here are snippets of my code, please advice!

 void Init_TimerA0(void)
{
  TAR = 65535 - 512; // 1 second => Timer will overflow
  TACTL = TASSEL_1+ID_3+MC_2; // ACLK + ACLK/8 + Continuous up count
  return;
}

void Enable_TimerA0(void)
{
  TACTL |= TAIE;
  //TACCTL0 |= CCIE;
  return;
}

#pragma vector = TIMERA1_VECTOR
__interrupt void TIMERA1ISR(void)
{
  TACTL &= ~TAIE;
  TACTL |= TACLR;
  P2OUT ^= P2OUT_1;  // Turn LED ON
  Init_TimerA0(); // Also called before while(1) loop!
  return;
}

 

  • Here is some sample code for the 430xG46x.

    Should be close...

    //****************************************************************************
    //  TA: Configure TA for a one-second interrupt
    //
    //  Instructions:
    //    configure Timer_A to give a 1s interrupt
    //
    //   - Set applicable TACTL bits to configure clock source and clear timer
    //   - Set applicable bits in TACCTL0 for compare mode, interrupt enabled
    //   - Load TACCR0 with #of counts to give 1s interrupt
    //
    //
    //
    //           MSP430FG461x
    //         ---------------
    //     /|\|            XIN|-
    //      | |               | 32kHz
    //      --|RST        XOUT|-
    //        |               |
    //        |           P2.1|-->LED (toggle at 1 second interval)
    //
    //******************************************************************************
    #include <msp430xG46x.h>

    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      FLL_CTL0 |= XCAP14PF;                     // Configure load caps
      P2DIR |= BIT1;                            // Set P2.1 to output direction
      TACTL = TASSEL_1 + TACLR;                 // Clock = ACLK (32768), clear
      TACCTL0 = CCIE;                           // CCR0 interrupt enabled
      TACCR0 = 32768-1;                         // #counts for 1s
      TACTL |= MC_1;                            // Setting mode bits starts timer

      _BIS_SR(LPM3_bits + GIE);                 // Enter LPM3 w/ interrupt
    }

    // Timer A0 interrupt service routine
    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
        P2OUT ^= 0x02;                          // Toggle P2.1 using exclusive-OR

  • I was trying not to use the TIMERA0 Vector.

    I figured out my problem, I forgot to enable TAIE after the first interrupt. The below lines of code works, if anyone else needs it!

    #pragma vector = TIMERA1_VECTOR
    __interrupt void TIMERA1ISR(void)
    {
      TACTL &= ~TAIFG;
      
      TAR = 0xFFFF - 512;
      //TACTL = TASSEL_1+ID_3+MC_2+TAIE; // ACLK + ACLK/8 + Continuous up count
      P2OUT ^= P2OUT_1;  // Turn LED ON
      return;
    }

**Attention** This is a public forum