• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » Launchpad S2 sets multiple Port 1 interrupt flags
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • Launchpad S2 sets multiple Port 1 interrupt flags

    Launchpad S2 sets multiple Port 1 interrupt flags

    This question is answered
    scott galvin
    Posted by scott galvin
    on Aug 06 2012 13:27 PM
    Prodigy20 points

    Hello, I am trying to have an MSP430G2203 in a launchpad perform 2 different operations. S2 should pulse led 2 when pressed. (this part works) The mode of the pulse is supposed to be determined by a switch on P1.4.

    However when I press S1 P1IFG is being set on bits 3,4,5 and in ISR runs through both if statements. This changes the "Mode" every time S2 is pressed.

    Here is my Code:

    /*
     * main.c
     */

    #include  "msp430g2203.h"


    #define Trigger     BIT3             // will change to P2.3 in final code
    #define ModeSwitch     BIT4            // will change to P1.0 in final code
    #define Solenoid     BIT6
    #define LED1        BIT0


    unsigned int Dwell=100000;
    unsigned int RateOfFire=100000;
    unsigned int Mode=0;

    void SetIO(void);
    void ConfigClocks(void);
    void FaultRoutine(void);

    void ModeSelect(void);
    void FullAuto(void);
    void SemiAuto(void);
    void ThreeBallBurst(void);
    void SixBallBurst(void);

    void main(void) {
        
          WDTCTL = WDTPW + WDTHOLD;            // Stop watchdog timer

          ConfigClocks();
          SetIO();

          while(1){
              _BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt
              }

    }

    void SetIO(void){

        P1DIR = Solenoid;                      // P1.6 output (solenoid fire)
        P1REN = 0;                            // Enable pull-up resistor
        P1OUT = 0;                          // outputs off

        //Set Input Interrupts
        P1IE |= (Trigger | ModeSwitch);     // P1.3 interrupt enabled
        P1IES |= (Trigger | ModeSwitch);     // P1.3 Hi/lo edge
        P1IFG &=~(Trigger | ModeSwitch);     // P1.3 IFG cleared

        P2DIR = 0X02;                        // set eyes output
        P2OUT = 0;                            // Turn off eyes
    }

    void ConfigClocks(void){

         if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
             FaultRoutine();                          // If calibration data is erased
                                                                 // run FaultRoutine()
               BCSCTL3 |= LFXT1S_0;                     // LFXT1 = Normal Operation
               IFG1 &= ~OFIFG;                          // Clear OSCFault flag
               BCSCTL2 |= SELM_3 + DIVM_0;               // MCLK = LXFT1/1

    }

    void FaultRoutine(void)
     {
       P1OUT = BIT0;                            // P1.0 on (red LED)
       while(1);                                 // TRAP
     }

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {

        if(P1IFG&Trigger){

            switch(Mode){
            case 0: SemiAuto();break;
            case 1: FullAuto();break;
            case 2: ThreeBallBurst();break;
            case 3: SixBallBurst();break;
            }

            //SixBallBurst();

        }
        if(P1IFG&ModeSwitch){
            ModeSelect();
        }
        P1IFG &= ~(Trigger | ModeSwitch);     // P1.3 and P1.4 IFG cleared
    }

    void ModeSelect(void){

            Mode +=1;

        if(Mode>3){
            Mode=0;
        }


    }

    void SemiAuto(void){

          P1OUT = Solenoid;                 // Turn On Solenoid
          //_delay_cycles(100000);            // SET THE "ON" TIME FOR SOLENOID

          P1OUT = 0X00;                     // Turn off Solenoid

    }

    void FullAuto(void){

        while ((P1IN & Trigger) == 0x00){
              P1OUT = Solenoid;                 // Turn On Solenoid
              _delay_cycles(100000);            // SET THE "ON" TIME FOR SOLENOID


              P1OUT = 0X00;                     // Turn off Solenoid
              _delay_cycles(100000);

        }

    }

    void ThreeBallBurst(void){

            int burst = 3;
            int count = 0;
            for (count=0;count <burst;count++){
                  P1OUT = Solenoid;                 // green LED on
                  _delay_cycles(100000);        // SET THE "ON" TIME FOR SOLENOID

                  P1OUT = 0X00;                      // green LED off
                  _delay_cycles(100000);

            }

    }

    void SixBallBurst(void){

            int burst = 6;
            int count = 0;
            for (count=0;count <burst;count++){
                  P1OUT = Solenoid;                 // green LED on
                  _delay_cycles(100000);        // SET THE "ON" TIME FOR SOLENOID

                  P1OUT = 0X00;                      // green LED off
                  _delay_cycles(100000);

            }

    }

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • old_cow_yellow
      Posted by old_cow_yellow
      on Aug 06 2012 14:17 PM
      Verified Answer
      Verified by scott galvin
      Guru25775 points

      When a port pin is (a) an input, (b) not connected to anything, and (c) not internally pullup/down, it might go up or down due to leakage or RF pickup. As a result, he corresponding IFG will be set too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • scott galvin
      Posted by scott galvin
      on Aug 07 2012 06:06 AM
      Prodigy20 points

      Thanks, I had set the P1REN=1 before but then I never got an interrupt when I pressed the button, so I thought I miss read the setting to be 0=enabled. I missed the part about P1OUT corresponding bits needing to be set to 1 also.

      I appreciate the Help as this was my first time posting a question.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use