• 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 » Stuck in the loop
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 >
  • Stuck in the loop

    Stuck in the loop

    This question is not answered
    abhishek Sabnis
    Posted by abhishek Sabnis
    on Aug 15 2012 15:30 PM
    Expert1185 points

    Hi,

    below  is the partial code that i am working on:

    #include <msp430g2452.h>

    void main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
    P1DIR = 0x07; // P1.0 output, else input
    P1OUT = 0x10; // P1.4 set, else reset
    P1REN |= 0x10; // P1.4 pullup

    while (1) // Test P1.4
    {
          if (0x10 & P1IN)
    { 

     P1OUT |= 0x01; // if P1.4 set, set P1.0
    P1OUT |= 0x02;
    P1OUT |= 0x04; 
    STUCK IN THIS  LOOP  FOREVER

    }
    else
    { 
    P1OUT &= ~0x01; // else reset
    P1OUT &= ~0x02;
    P1OUT &= ~0x04; 
    } 

    }
    }

    The problem is STUCK IN THIS  LOOP  FOREVER. Even if input pin P1.4 reset the program is stuck in the P1.4 set loop. I am using TI MSP430G2352.

    Please let me know what will be wrong potentially.


    Thanks,


    Abhishek

    Report Abuse
    • Reply
    You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    All Replies
    • abhishek Sabnis
      Posted by abhishek Sabnis
      on Aug 16 2012 08:14 AM
      Expert1185 points

      Anybody has any recommendations on given issue. 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mo.
      Posted by Mo.
      on Aug 16 2012 10:52 AM
      Genius10245 points

      abhishek Sabnis
      P1REN |= 0x10; // P1.4 pullup

      This will always result to a logic HIGH at P1.4 if this input is floating (unconnected).

      You will get a Logic LOW at the P1.4 input if you pull this pin to Ground.

      BR,

      Mo.

      Make The Switch to TI MCUs

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 17 2012 08:40 AM
      Guru140135 points

      Mo already explained why you're always entering this branch: P1.4 is configured as input, pulled high by internal pullup resistor (P1REN |=0x10 / P1OUT = 0x10). So (P1IN & 0x10) is always true unless you externally pull the pin down to GND. If you do so, you'll seem stuck in the else branch instead.

      abhishek Sabnis
       P1OUT |= 0x01; // if P1.4 set, set P1.0
      P1OUT |= 0x02;
      P1OUT |= 0x04; 

      This code is unnecessarily long and also leads to a larger program than necessary (the compiler is forced to generate separate access code for each access of a hardwar eregister).

      P1OUT |= (BIT0 | BIT1 | BIT2);

      will result in only one write access of all three btis simultaneously (smaller and faster). The use of BITx isntead oc numeric values also makes clear that you doN't want to write a number, but rather want to set specific (port) bits.

      Similarly, the code in the else can be simplified to

      P1OUT &= ~ (BIT0 | BIT1 | BIT2);

      Note that I'm not adding the bits. While BIT0+BIT1 is the same as BIT0|BIT1, there is a huge difference between BIT0+BIT0 (== BIT1)  and BIT0|BIT0 (==BIT0). Since you're setting bits and not adding values, the use of | shol dbe preferred to 'group' bits instead of adding them with an addition.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • abhishek Sabnis
      Posted by abhishek Sabnis
      on Aug 17 2012 08:47 AM
      Expert1185 points

      Jens and Mo,

      Thanks for suggestions. I have mosfet driving port 1.4. so externally , MOSFET is pulling down P1.4 to 0. The thing is it seems to go in respective loops some times but sometimes it gets stuck in same loop even if P1.4 changes. I have no other inputs other than P1.4.

      Thanks,

      Abhi 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on Aug 17 2012 10:01 AM
      Guru140135 points

      Thsi is strange.

      The compiler won't 'cache' the value of P1IN. And the hardware won't cache it too. So if the input pin changes below the low-going threshold voltage, P1IN.4 will be reset and the code should properly execute the else branch.

      So I'd say check your hardware. Best do a check of the P1,4 pin voltage with a scope. A logic analyzer might interpret high and low differently than the MSP if the signal is in a critical range.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • abhishek Sabnis
      Posted by abhishek Sabnis
      on Aug 17 2012 10:07 AM
      Expert1185 points

      Jens,

      I monitored P1.4 on scope. It changes from 3.3V to 0V upon transition but some how outputs wont, they are staying in the same state. 

      One more thing have 3 outputs who changes its state depending upon input signal at P1.4 

      1. one output drives LED

      2. Drives  Relay

      3. pushpull Controller through mosfet.

      Do you think i have noise problem? i am monitering VCC but its stable, i am sure that micro is resetting. 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Tony Philipsson
      Posted by Tony Philipsson
      on Aug 17 2012 10:28 AM
      Intellectual760 points

      I think your board design with it's mosfet is probably wrong, learn more about pull-up and how to sink it. 

       

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • old_cow_yellow
      Posted by old_cow_yellow
      on Aug 17 2012 11:15 AM
      Guru25735 points

      You could test your code on LaunchPad.

      LaunchPad board has LEDs at P1.0 and P1.6. And a push-button that grounds P1.3 when pushed. You only need very small changes in your code to accommodate the above I/O pin assignments. 

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Mo.
      Posted by Mo.
      on Aug 18 2012 16:48 PM
      Genius10245 points

      abhishek Sabnis
      I have mosfet driving port 1.4. so externally , MOSFET is pulling down P1.4 to 0. The thing is it seems to go in respective loops some times but sometimes it gets stuck in same loop even if P1.4 changes. I have no other inputs other than P1.4.

      since you are polling an pin input state in a while loop, I would suggest you to enable the interrupt at this pin to see if you get the interrupt upon a high-low transition on this pin.

      BR,

      Mo.

      Make The Switch to TI MCUs

      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