Page 1 of 1

[SOLVED]MSP430 Interrupts

Posted: Fri May 06, 2011 2:30 pm
by regomodo
[EDIT] I Found out why it wasn't working. My code was practically there but lacked 2 lines to do with the CPUs Status Register. This post explains it better than I could. My code has been edited to reflect this info.


Hello,

I'm eventually getting round to making use of the Launchpads I bought and i've hit a stumbling block on a relatively easy task: IO interrupts.
I have tried to use the interrupt examples out there but my compiler (mspgcc4) fails with the following error:
Code: Select all
msp430-gcc -Os -Wall -g -mmcu=msp430x2211 -c main.c
main.c:14: warning: return type of 'main' is not 'int'
main.c: In function 'main':
main.c:25: warning: implicit declaration of function '_enable_interrupt'
main.c: At top level:
main.c:39: warning: ignoring #pragma vector 
main.c:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'
make: *** [main.o] Error 1
Instead i slightly modified it using a Timer interrupt program that worked. However, my pin interrupt just seems to do nothing, but at least it compiles. The code is:
Code: Select all
 
#include <io.h>
#include <signal.h>
#define LED1 BIT0
#define LED2 BIT6
#define BUTTON BIT3


int main(void)
{
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1DIR |= (LED1 + LED2); // set leds as outputs
    P1REN |= BUTTON; // enable internal pullup
    P1OUT |= BUTTON; // set pullup
    P1OUT &= ~(LED1 + LED2); // turn off leds
    
    P1IES |= BUTTON; // high to low
    P1IE |= BUTTON; // enable interrupt
    P1IFG &= ~BUTTON; // clear interrupt flag

    __bis_SR_register(LPM0_bits + GIE); // enable global interrupts & go into low-power mode

    while(1);
}


interrupt(PORT1_VECTOR) PORT_1(void)
{
    P1OUT ^= (LED1|LED2);
    P1IFG &= ~BUTTON;
    __bis_SR_register_on_exit(LPM0_bits); // ensures low-power mode on exit

}
The only bits i'm not certain about is whether I should use an internal pullup (P1REN) and how to use the interrupt. Can anybody help?