Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Interrupt help.

$
0
0

Hi, 

 

I have posted about this before but I am still struggling :(

 

I want my code to:

 

Be in LPM until it detects an input on P1.3

When an input on P1.3 and P1.5 are present execute code which turns on P1.5 for a count of i

go back into LPM

 

What I don't understand is what the interrupt is actually DOING. By this I mean I know the code below is the interrupt routine on Port 1 but is this waking the 430 up? Should my code I want to execute whilst the 430 is awake go in here or somewhere else? 

 

        // Port 1 interrupt service routine

         #pragma vector=PORT1_VECTOR

         __interrupt void Port_1(void)

 

Also what does the interrupt flag actually do?

 

P1IFG &=~BIT3;                        // P1.3 IFG cleared

 

 

When I compile my program it compiles ok, but there is obviously something a miss as when I operate it on a 430 it doesn't work. I have read the MSP430x2xx family manual and looked at various examples online but still cannot figure out where i'm going wrong. 

 

Thanks for your help. 

 

 

 

 

FULL CODE BELOW:

 

#include <msp430.h>

 

/*

 * main.c

 */

 

volatile long int i;

 

int main(void) {

    WDTCTL = WDTPW | WDTHOLD;                                 // Stop watchdog timer

    CCTL0 = CCIE;                             // CCR0 interrupt enabled

    TACTL = TASSEL_2 + MC_1 + ID_3;           // SMCLK/8, upmode

 

    P1SEL = 0x00;                                                              // setting all P1 pins to GPIO

 

    P1DIR |= BIT2;                            // Set P1.2 to output direction. The rest are input.

    P1REN |= BIT3;                                                             // Enable Pullup Res on P1.3

    P1OUT |= BIT3;                                                             // Select pullup mode for P1.3 set to "1" in non-operated state.

 

    // INTERRUPTS

    P1IE |= BIT3;                                                              // Enable Interrupt on P1.3

    P1IES |= BIT3;                                                             // HI->LOW edge

    P1IFG &= ~BIT3;                                                    // Clears interrupt flag (IFG) on P1.3

 

    P1IN =BIT2;                                                        // Set P1.2 to LOW

    P1OUT =BIT5;                                                           // Set P1.5 to LOW

 

    _BIS_SR(CPUOFF + GIE);                           // Enter LPM0 w/ interrupt

      while(1)                                //Loop forever, we work with interrupts!

      {}

}

 

         // Port 1 interrupt service routine

         #pragma vector=PORT1_VECTOR

         __interrupt void Port_1(void)

         {

                          P1OUT |= BIT2;                                     // set P1.2 high

                          i=15000;

                         do(i--);

                         while (i !=0);

                          P1OUT &= ~BIT2;                                             // set P1.2 to low

 

                          P1IFG &=~BIT3;                        // P1.3 IFG cleared

         }


Viewing all articles
Browse latest Browse all 2077

Trending Articles