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.

CCS/MSP430FR2311: GPIO Interrupt Pin 2.6 LPM

Part Number: MSP430FR2311

Tool/software: Code Composer Studio

I'm trying to get the launchpad to go into LPM3 unless it receives a high signal (3.3V) from pin 2.6 ( I have an LED turning on so that I can see it on the launchpad) which is a GPIO interrupt pin.
I have pin 2.6 connected to the ON signal from a xbee module. Not sure if I am setting up my interrupt vector correctly.Thanks in advance.

 

 

#include <msp430.h>

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
// Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
P1DIR |= BIT1; // Set P1.0 to output direction


P2DIR &= ~BIT6; 
P2REN &= ~BIT6;
P2IES &= ~BIT6; // P2.6 Lo/High edge
P2IE |= BIT6;
P2IFG &= ~BIT6;
__bis_SR_register(GIE);          // Global interrupts Enable


}

// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port2_ISR(void)
{

    P2IFG &= ~BIT6; // Clear P2.6 IFG
    P1OUT |= BIT0; // led ON

__bic_SR_register_on_exit(LPM3_bits); // Exit LPM3
}

  • Hi Sparrow,

    //#include <msp430.h>
    //
    //int main(void)
    //{
    //    WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
    //    // Disable the GPIO power-on default high-impedance mode
    //    // to activate previously configured port settings
    //    PM5CTL0 &= ~LOCKLPM5;
    //    P1DIR |= BIT0; // Set P1.0 to output direction
    //
    //
    //    P2DIR &= ~BIT6;
    //    P2REN &= ~BIT6;
    //    P2IES &= ~BIT6; // P2.6 Lo/High edge
    //    P2IE |= BIT6;
    //    P2IFG &= ~BIT6;
    //    __bis_SR_register(GIE);          // Global interrupts Enable
    //
    //
    //}
    //
    //// Port 2 interrupt service routine
    //#pragma vector=PORT2_VECTOR
    //__interrupt void Port2_ISR(void)
    //{
    //
    //    P2IFG &= ~BIT6; // Clear P2.6 IFG
    //    P1OUT |= BIT0; // led ON
    //
    //    __bic_SR_register_on_exit(LPM3_bits); // Exit LPM3
    //}
    
    
    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    
        // Configure GPIO
        P1OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
        P1DIR |= BIT0;                          // Set P1.0 to output direction
    
        P2OUT &= ~BIT6;                         // Configure P2.6 as pulled-down
        P2REN |= BIT6;                          // P2.6 pull-down register enable
        P2IES &= ~BIT6;                         // P2.6 Low/High edge
        P2IE |= BIT6;                           // P2.6 interrupt enabled
    
        // Disable the GPIO power-on default high-impedance mode
        // to activate previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        P2IFG &= ~BIT6;                         // P2.6 IFG cleared
    
        while(1)
        {
            __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/interrupt
            __no_operation();                   // For debug
    
        }
    }
    
    // Port 2 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=PORT2_VECTOR
    __interrupt void Port_2(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
    #else
    #error Compiler not supported!
    #endif
    {
        P2IFG &= ~BIT6;                         // Clear P2.6 IFG
        P1OUT ^= BIT0;                          // P1.0 = toggle
        __bic_SR_register_on_exit(LPM3_bits);   // Exit LPM3
    }
    
    

    Regards,

    Ling

  • Thank you very much for your response. This cleared up for me how to set up the pull down resistor.

    However, whenever I run this code and apply 3.3V to pin2.6 it turns on the LED (not toggles it) on every OTHER rising edge. I want it to turn on when 3.3V is applied and the LED to turn off when it's not.

    Any solutions as to why it maybe reading every other rising edge?
  • I suppose the "every other" effect comes from

    > P1OUT ^= BIT0; // P1.0 = toggle

    I think you're free to replace this with code of your choosing. One possibility is to reverse the interrupt sense in P2IES, perhaps after some debouncing.
  • Sparrow Tech said:
    Thank you very much for your response. This cleared up for me how to set up the pull down resistor.

    However, whenever I run this code and apply 3.3V to pin2.6 it turns on the LED (not toggles it) on every OTHER rising edge. I want it to turn on when 3.3V is applied and the LED to turn off when it's not.

    Any solutions as to why it maybe reading every other rising edge?

    #include <msp430.h>
    
    int main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;               // Stop watchdog timer
    
        // Configure GPIO
        P1OUT &= ~BIT0;                         // Clear P1.0 output latch for a defined power-on state
        P1DIR |= BIT0;                          // Set P1.0 to output direction
    
        P2OUT &= ~BIT6;                         // Configure P2.6 as pulled-down
        P2REN |= BIT6;                          // P2.6 pull-down register enable
        P2IES &= ~BIT6;                         // P2.6 Low/High edge
        P2IE |= BIT6;                           // P2.6 interrupt enabled
    
        // Disable the GPIO power-on default high-impedance mode
        // to activate previously configured port settings
        PM5CTL0 &= ~LOCKLPM5;
    
        P2IFG &= ~BIT6;                         // P2.6 IFG cleared
    
        __bis_SR_register(GIE);
    
        while(1)
        {
    //        __bis_SR_register(LPM3_bits | GIE); // Enter LPM3 w/interrupt
            __no_operation();                   // For debug
    
            if(!(P2IN&BIT6))
                P1OUT &= ~BIT0;
    
        }
    }
    
    // Port 2 interrupt service routine
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=PORT2_VECTOR
    __interrupt void Port_2(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(PORT2_VECTOR))) Port_2 (void)
    #else
    #error Compiler not supported!
    #endif
    {
        P2IFG &= ~BIT6;                         // Clear P2.6 IFG
        P1OUT |= BIT0;                          // P1.0 = 1
    //    __bic_SR_register_on_exit(LPM3_bits);   // Exit LPM3
    }
    

**Attention** This is a public forum