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.

Timer interrupt problem

Other Parts Discussed in Thread: MSP430G2553, IAR-KICKSTART

Hi,

I am looking for a simple example on how to use the timer and interrupts on the M430G2553. I have used timers and interrupts on other microcontrollers and compilers but am having difficulty compiling the examples I have found on the net for the M430G2553 on CCS.

I have created a new project on CCS v6.1 for the M430G2553 and entered the following based on an example I found on the internet ( I just changed the header file to msp430g2553):

/*
 * MSP430 Timer Tutorial Example Code 1
 * Anthony Scranney
 * www.Coder-Tronics.com
 * August 2014
 *
 * Switching the MSP430G2253 Launchpad LED's on and off
 */

#include <msp430g2553.h>

int Control = 0;

int main(void) {

	/*** Watchdog timer and clock Set-Up ***/
	WDTCTL = WDTPW + WDTHOLD;		// Stop watchdog timer
	DCOCTL = 0;             		// Select lowest DCOx and MODx
	BCSCTL1 = CALBC1_1MHZ;  		// Set range
	DCOCTL = CALDCO_1MHZ;   		// Set DCO step + modulation

	/*** GPIO Set-Up ***/
    P1DIR |= BIT0;					// P1.0 set as output
    P1OUT &= ~BIT0;					// P1.0 set LOW (Red LED)
    P1DIR |= BIT6;					// P1.6 set as output
    P1OUT &= ~BIT6;					// P1.6 set LOW (Green LED)

	/*** Timer0_A Set-Up ***/
    TA0CCR0 |= 3000;					// Counter value
    TA0CCTL0 |= CCIE;				// Enable Timer0_A interrupts
    TA0CTL |= TASSEL_1 + MC_1;		// ACLK, Up Mode (Counts to TA0CCR0)

    _BIS_SR(LPM0_bits + GIE);		// Enter Low power mode 0 with interrupts enabled
}

#pragma vector=TIMER0_A0_VECTOR     // Timer0 A0 interrupt service routine
   __interrupt void Timer0_A0 (void) {

	   Control++;
	    P1OUT ^= BIT0;					// P1.0 Toggle (Red LED)

	   if (Control == 4)
	   {
	    P1OUT ^= BIT6;					// P1.6 Toggle (Green LED)
	    Control = 0;
	   }
}

When I compile I receive the following error at the interrupt service routine on line 37:

expected '=', ',', ';', 'asm' or '__attribute__' before 'void'

I receive the same error when trying to compile other example programs using the timer and interrupts. Looking at the header file msp430g2553.h shows that TIMER0_A0_VECTOR is correct. 

Could someone please point out what is wrong in the code above or provide a very simple example using the timer and interrupts for the MSP430G2553. I just need to know the correct way to include the interrupt service routine in my code. 

Dan



 

  • I found the following example code in the Resource Explorer, which has a wealth of example code (a great feature):

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P1DIR |= 0x01;                            // P1.0 output
      CCTL0 = CCIE;                             // CCR0 interrupt enabled
      CCR0 = 60000;
      TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0 w/ interrupt
    }
    
    // Timer A0 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=TIMER0_A0_VECTOR
    __interrupt void Timer_A (void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
    #else
    #error Compiler not supported!
    #endif
    {
      P1OUT ^= 0x01;                            // Toggle P1.0
      CCR0 += 60000;                            // Add Offset to CCR0
    }

    It works. Will I have to code each ISR as in the code above?

    Dan

  • Are you using the gcc compiler rather than TI's compiler? The first example you posted is for the TI compiler only, the second one works with the TI, IAR and gcc compilers.
  • Thank you for your reply Robert. That was the problem; I am using the gcc compiler. I modified the second example and it works:

    #include <msp430.h>
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P1DIR |= 0x01;                            // P1.0 output
      CCTL0 = CCIE;                             // CCR0 interrupt enabled
      CCR0 = 40000;
      TACTL = TASSEL_2 + MC_2;                  // SMCLK, contmode
    
      __bis_SR_register(LPM0_bits + GIE);       // Enter LPM0 w/ interrupt
    }
    
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A (void)
    {
      P1OUT ^= 0x01;                            // Toggle P1.0
      CCR0 += 40000;                            // Add Offset to CCR0
    }
    

    When I create a new project, the only compiler available in the drop down box is "GNU v4.9.1 (Red Hat)". Is the TI compiler only available on purchased software?

    Dan

  • Control++;
    if (Control == 4)
    Control = 0;

    Side note, those 3 lines could be replaced with a single: if (!( ++Control & 3));
    PS only work with (powerof2 -1) values like: 3,7,15,31...
  • The CCSTUDIO-MSP page says:

    A free license will be generated that supports a 16KB code size limit for the optimized TI compiler on MSP430 and 32KB on MSP432. A 90-day full featured evaluation license is also available. GCC releases for MSP430 and MSP432 are available from the App Center inside CCS and can be used with the free license.

    The IAR-KICKSTART page says:

    IAR Embedded Workbench Kickstart for MSP is a complete debugger and C/C++ compiler toolchain for building and debugging embedded applications based on MSP430 and MSP432 microcontrollers. The code size limitation of C/C++ compiler is set to 8 KB for MSP430 devices
  • Thank you Clemens.

    Regards,

    Dan

**Attention** This is a public forum