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.

Problem entering timer interrupt (TIMER0_A0_VECTOR)

Other Parts Discussed in Thread: MSP430G2553

Hello everyone,

I just started with programming microcontrollers with the Launchpad MSP430 and CCS. I have the MSP430G2553 chip.

I tried to follow this tutorial:

http://homepages.ius.edu/RWISMAN/C335/HTML/msp430Timer.HTM

 which shows how to work with interrupts to get the two LEDs to flash. I copy and pasted the code from section 15. (Toggle red LED every two seconds/green LED every second. ):

 #include <msp430g2553.h>

void main(void) {

  WDTCTL = WDTPW + WDTHOLD;        // Stop watchdog timer

  P1DIR |= BIT0;                   // Set P1.0 to output direction
  P1OUT &= ~BIT0;                  // Set the red LED off

  P1DIR |= BIT6;                   // Set P1.6 to output direction
  P1OUT &= ~BIT6;                  // Set the green LED off

  TA0CCR0 = 12000;                 // Count limit (16 bit)
  TA0CCTL0 = 0x10;                 // Enable Timer A0 interrupts, bit 4=1
  TA0CTL = TASSEL_1 + MC_1;        // Timer A0 with ACLK, count UP

  TA1CCR0 = 24000;                 // Count limit (16 bit)
  TA1CCTL0 = 0x10;                 // Enable Timer A1 interrupts, bit 4=1
  TA1CTL = TASSEL_1 + MC_1;        // Timer A1 with ACLK, count UP

  _BIS_SR(LPM0_bits + GIE);        // LPM0 (low power mode) interrupts enabled

}

#pragma vector=TIMER1_A0_VECTOR    // Timer1 A0 interrupt service routine

  __interrupt void Timer1_A0 (void) {

   P1OUT ^= BIT0;                  // Toggle red LED
}

#pragma vector=TIMER0_A0_VECTOR    // Timer0 A0 interrupt service routine

  __interrupt void Timer0_A0 (void) {

   P1OUT ^= BIT6;                  // Toggle green LED
}

It all seemed pretty straighforward to me, but somehow, the second interrupt routine(#pragma vector=TIMER0_A0_VECTOR) is never entered and the green LED never flashes. The first interrupt is entered (which I can see during step by step debug) and the red LED flashes just fine.

I found several other tutorials (eg. http://www.egarante.net/2010/09/msp430-launchpad-tutorial-part-2.html ) that have that vector named #pragma vector=TIMERA0_VECTOR , but if I try this, I get an error '#20 identifier "TIMERA0_VECTOR" is undefined'.

Which vectors / timers do I even have on the MSP430G2553 chip? Is it maybe possible that I don't have a TIMER0_A0_VECTOR timer?

Any help is appreciated!

  • Sven,

    i know the vector naming is a little bit difficult to understand, and that's why i put it on the FAQ wiki:

    http://processors.wiki.ti.com/index.php/MSP430_FAQ#How_to_assign_the_correct_Timer_A_interrupt_vector.3F

    I just tried to compile your code as is on my Launchpad MSP-EXP430G2 v1.3 with MSP430G2553, and i can see both LEDs blink. 

    Have you made sure that the J5 jumpers are connected on the board?

  • Hello Leo,

    yes, both jumpers are connected. Also, the green LED does blink if I put the code in the interrupt routine for TIMER1_A0_VECTOR. So it's not the output that doesn't work, just the interrupt routine for TIMER0_A0_VECTOR is never entered.

    Are there any other things that need to be modified on the board? I have the Launchpad MSP-EXP430G2 v1.5, could it be a version thing?

  • I just tried this code on a Rev 1.5 board, and both LEDs blink, but very slowly (10x period?) and erratically.

    I added this line up at the beginning of main():

             BCSCTL3 |= LFXT1S_2;                // VLOCLK

    and the LEDs behave as expected.This forces the ACLK to use the VLOCLK rather than the 32kHz

    (LFXT1) crystal oscillator; if you don't have a crystal on-board (I don't) ACLK will eventually fail-over

    when the 32kHz oscillator doesn't start, but I haven't experimented with how long (or how often)

    that is.

  • Sven,

    i think Bruce is right. After testing it further, i also see the symptomp described by him. I would also suggest to assign the ACLK to be sourced by VLOCLK if you don't have any 32 kHz crystal attached at XT1 on the launchpad.

  • Bruce McKenney47378 said:
    if you don't have a crystal on-board (I don't) ACLK will eventually fail-over when the 32kHz oscillator doesn't start, but I haven't experimented with how long (or how often)

    If you don't have a crystal, the MSp wills till try to launch it. which will cause clock pulses to be counted for ACLK, but rather eratically, as XIN is jsut an open antenna and will just receive crosstalk from XOUT and other circuitry. And maybe even radio waves :).
    This would explain the erratic behaviour of the LED.

    On 5x family, ACLK will fall back to REFO when no crystal is there (In LFXT1 mode, else it will fall back to DCODIV).

**Attention** This is a public forum