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.

Me or compiler having a bad day?

I am trying to run a very simple program that lightens two LEDs on the exp4618 board when I push a button, but the compiler seams to ignore my while(1) forever loop, somehow the program excecute the P2OUT=0x00; row every time I have pushed the button and the LEDs are turned off again...

Very disturbing, is there any optimizations setting in the compiler that must be changed so that while(1) is not ignored??

#include "msp430xG46x.h"

 

void main(void)

{

P1DIR&=0xFD;

P2DIR|=0x06;

 

P2OUT=0x00;

           

while(1)

      {

      if ((P1IN | 0xFD)==0xFD)

            {

            P2OUT=0x06;

            }

      }

}

 

  • Seams to be the fact that I am running in "Debug" mode...cannot understand the advantage of having "Debug" and "Release" settings, especially if the "Debug" mode makes while(1) loops to behave very strange...

    I am new to Code Composer Studio so maybe I will understand it later...

     

  • Hi trewq,

    Pls have a look at this (http://wiki.msp430.com/index.php/EZ430-F2013) and try the 'New project guide'. This will ease your live when your new to CCS.

    Rgds
    aBUGSworstnightmare

  • I am not a beginner with IDE tools but now I feel like one....

    I still have problems with the code above again, changing to "Release" mode only helped once...

    Debugging or not the program somehow thinks its a good idea to jump out of the while(1) without any break condition...I am going crazy here!

    Many other problems also, nothings seams to work correctly....

    Using Code Composer Studio V.4

     

     

  • Trewq,

    I think the MSP is resetting due to the enabled watchdog timer. Typically we add the following line at the beginning of main():

      // Stop watchdog timer to prevent time out reset
      WDTCTL = WDTPW + WDTHOLD;

    Can you try to add this and see if the issue disappears?

    Cheers,

    Rafael

     

  • I'm guessing it's your  'if' statement.  Since P1IN is a 'read-only' register, attempting bit manipulations on it (bitwise or with 0xfd) may not work.  Try reading P1IN into a variable, then performing your logic operations.   Hope this helps.

    Cheers,

    Clark Molster

    Texas Instruments

  • Thanks desouza, i was not aware of that the watchdog would think that code was a "freeze" and it was enabled as default....

    Resetting the watchdog counter every loop in main also works...WDTCTL=WDTPW+WDTCNTCL;