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.

MSP430G2352 Timer Interrupts

Other Parts Discussed in Thread: MSP430G2352

Hello, 

i am triing to use Timer interrupts in my code, but i just dont get how to write the interrupt service routine.

I am using the MSP430G2352 and have tried this code:

#pragma vector=TIMER_A_VECTOR
__interrupt void Timer_A (void)

But it gives me an error in the first line, guess the vector is wrong, copied it from another example cause i did not find anything. 

So my question: Where can i look up the Vector Addresses for the Interrupts ( some kind a datasheet maybe ) ?

Thank you very much :)

  • Jan Steiners said:
    But it gives me an error in the first line, guess the vector is wrong, copied it from another example cause i did not find anything. 

    Perhaps did not look carefully enough.

    Web page of chips you are using:

    http://www.ti.com/product/MSP430G2352

    Have Source Code Examples in "Software section":

    http://www.ti.com/lit/zip/slac467

    That have lot of timer examples such as "msp430x20x3_ta_07.c"

    where you can see that correct interrupt routine is as follows:

    // Timer_A2 Interrupt Vector (TAIV) handler
    #pragma vector=TIMERA1_VECTOR
    __interrupt void Timer_A1(void)
    {
    // insert your code here
    }

  • Hi,

    thank you very much for your help, but it still does not work :(

    IAR gives me an Error: TIMERA1_VECTOR is undefined ... dont know what to do anymore :/

    Also, is there any datasheet that shows me a complete list of the vectors?

    Thank you

  • Jan Steiners said:
    Also, is there any datasheet that shows me a complete list of the vectors?

    Datasheet does not define interrupt vectors for C compiler. Did you try to download source code examples and compile some?

    Thing is that interrupt vectors are defined in C header files having ".h" extension. You just have to "include" correct one in very beginning of your .c source file. Like:

    #include <msp430.h>

  • I found out my mistake (forgot to change my device in the IAR options.....*headbutt*)

    But uhm, its still not working, i dont know if my code is wrong or the vector, so maybe you could have a look at it, ill just post the code here .... thank you very much :)

    #include <msp430G2352.h>
    
    
    unsigned char beat = 10;
    int i;
    int main( void )
    {
      // Stop watchdog timer to prevent time out reset
      WDTCTL = WDTPW + WDTHOLD;
      
      P1OUT = 0x00; //LEDs off
      P1REN = 0x00; //Set P1.3 on High
      P1DIR = 0x41; // LEDs output
      TACTL = 0x0012;    // Timer on, Divier 8, ACLK, Count Mode
      TAR = 0x9FFF;  // Timer for 10BPM Start(Overflow after 6 secs)
      
      while(1)
      {
        
        if ((P1IN & 0x08) == 0x00)           //If pushed 
        {        
            TACTL = TACTL & 0xFFCF;          //Timer off              
            beat = beat + 10;               //BPM +10         
            if(beat == 110) beat = 10;      //if BPM == 110, BPM = 10
            TAR = (0xFFFF - ((60/beat) * 0x1000 )); //New start,depending on beat
            while((P1IN & 0x08) == 0x00);    //Wait for button released
            TACTL = TACTL | 0x0010;         //Timer on
                  
        }   
      }
    }
    
    // Timer A0 interrupt service routine
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A0 (void)
      {
             TACTL = TACTL & 0xFFCF;        //Timer off
             TACTL = TACTL & 0xFFFE;        //Delete Interrupt Flag
             TAR = (0xFFFF - ((60/beat) * 0x1000 )); //New tart, depending on beat
             TACTL = TACTL | 0x0010;         //Timer on
             P1OUT = 0x40;                  //LED on
             for(i=0;1024;i++);             //wait 2,5 sec
             P1OUT = 0x00;                  //LED off
      }

  • Jan Steiners said:
    But uhm, its still not working

    Worst information you can give: no information at all. You shall be as detailed as possible - what exactly does not happen as you expect?

    Well, perhaps your delay loop is not right:

           for(i=0;1024;i++);             //wait 2,5 sec

    it's "end" condition is 1024 which means TRUE forever so it never ends. BTW compiler shall complain/warn about this

  • OK, ill change that, but if that would be the problem, the LED would at least go on ;)

    In debug mode the statements seem to work, only thing that made me wonder was, that the TA0R Register did not count up, it always sticks to 0x9FFF ... is that normal? (Sorry im a total newcomer to the MSP430)

  • Jan Steiners said:
    only thing that made me wonder was, that the TA0R Register did not count up, it always sticks to 0x9FFF

    If you wonder about timer operation then write code which does nothing else than timer operation. At the moment what you do with timer is honestly - frustrating

  • Jan Steiners said:
    #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0 (void) { TACTL = TACTL & 0xFFCF; //Timer off TACTL = TACTL & 0xFFFE; //Delete Interrupt Flag TAR = (0xFFFF - ((60/beat) * 0x1000 )); //New tart, depending on beat TACTL = TACTL | 0x0010; //Timer on P1OUT = 0x40; //LED on for(i=0;1024;i++); //wait 2,5 sec P1OUT = 0x00; //LED off }

    Deleting the interrupt flag at the start of operation is a big no to me... Why do that? Timer Interrupt flag will be cleared automatically when the ISR is reaching its endline. Clearing it before may cause the CPU to exit the ISR prematurely.

    Also... why did you turn off the timer at the ISR? I don't get what are you trying to do here...

  • I worked with another Microcontroller before where the interrupt flag had to be cleared by software, that confused me a bit ... turning the timer off was just for test purpose for myself :)

    I got it work now anyway, thanks for the help guys

  • Jan Steiners said:
    I worked with another Microcontroller before where the interrupt flag had to be cleared by software,

    THis is still true for most MSP interrupts. Only the timer CCR0 interrupt and the ADC10 interrupt auto-clear the interrupt flag on ISR start. Because there is only one single trigger that could have caused this interrupt and it saves you a few CPU cycles if the hardware clears the bit.

    All others need to either clear the bit manually or by action (e.g. writing to TXBUF or reading RXBUF) or by reading the interrupt vector register (e.g. TA0IV) which will return the number of the highest pending interrupt for this module and at the same time clearing this interrupt flag.

**Attention** This is a public forum