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.

Basic getting started question

Other Parts Discussed in Thread: MSP430FG439

I am just getting started. I have a MSP430FG439. I am using the IAR embedded workbench. I have a basic program that should toggle a port pin shown below. I am able to complie, build and link my source code , then I can download and debug with no errors....but using a scope, I don't see any signal on the port pin. This makes me think I am not really running from the target hardware but running a simulator .....any help would be appreciated

#include  <msp430xG43x.h>

void main(void)
{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P5DIR |= 0x02;                            // P5.1 output
  CCTL0 = CCIE;                             // CCR0 interrupt enabled
  CCR0 = 20000;
  TACTL = TASSEL_2 + MC_1;                  // SMCLK, up mode
  _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
}

// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  P5OUT ^= 0x02;                            // Toggle P5.1 using exclusive-OR
}

  • Hello Steve,

    Just do one change in the this code.

     

    Please refer below

    #include  <msp430xG43x.h>

    void main(void)
    {

      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P5DIR |= 0x02;                            // P5.1 output
      CCTL0 = CCIE;                             // CCR0 interrupt enabled
      CCR0 = 20000;
      TACTL = TASSEL_2 + MC_1;                  // SMCLK, up mode

    while(1)

    {

    }
      _BIS_SR(LPM0_bits + GIE);                 // Enter LPM0 w/ interrupt
    }

    // Timer A0 interrupt service routine
    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
      P5OUT ^= 0x02;                            // Toggle P5.1 using exclusive-OR
    }

  • Steve,

    The code Harshal provided will loop indefinitely and never reach the LPM0. I'm not sure this will fix your problem. I do not know IAR too well, but I imagine this is a problem with releasing the MSP430 from the debugger. How do you test y our code exactly? Does the scope see the values when you run in the debugger?

    NJC
    _______________________

    http://msp430launchpad.com

  • Steve ,

    You can comment out the low power mode commad.

    As you say you just learning the core.

    Why do you want to put MCU in loew power mode if you are at very basic stage.

    I forgot to comment out that line while replying to you otherwise you can put that line inside the while loop and test the code

  • Just comment out that low power mode command and test code it will run perfectly

     

  • Guys,

     

    I think you have something wrong:

     

    In the code above , the code will enter the infinite while loop and the _BIS_SR(LPM0_bits + GIE); will never be executed so that the timer will not run. This is because the time interrupt routine requires that the interrupts be set.  the code should be as follows:

     

    #include  <msp430xG43x.h>

    void main(void)
    {

      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P5DIR |= 0x02;                            // P5.1 output
      CCTL0 = CCIE;                             // CCR0 interrupt enabled
      CCR0 = 20000;
      TACTL = TASSEL_2 + MC_1;                  // SMCLK, up mode

    while(1)

    {

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

    }
     
    }

    // Timer A0 interrupt service routine
    #pragma vector=TIMERA0_VECTOR
    __interrupt void Timer_A (void)
    {
      P5OUT ^= 0x02;                            // Toggle P5.1 using exclusive-OR
    }

    putting the _BIS_SR(LPM0_bits + GIE);       inside the while loop or before it is an acceptable solution since it will avoid stopping if for some reason the interrupt vector causes an exit from the LPM.

     

    Another solution, if you want to do some processing during the timer running is to use __EINT();  (check the spelling of it, it might need only one underscore).
    Remember that what you need is to enable interrupts, it just so happens that you can also go to low power mode too.

    Looking at the original post, the code seems ok. However, if you're afraid you're running the simulator, change the project settings to FET Debugger instead of simulator. You can sometimes notice that the simulator is executing and not the JTAG FET because when the simulator is being used, the part of the debugger where it says downloading and such runs much faster since it doesn't really do any of that.

    To check the project settings in IAR right click on project name and click on settings. There is a tab for FET Debugger or something similar. A good way to start learning is with some tutorials. I have a tutorial (that still needs a lot of work but gets a lot of the basics ) at:

    http://www.utdallas.edu/~gustavo.litovsky/Tutorialv0_2.pdf

    There are also plenty of resources out there for the MSP430

    GL

  • OK, I found the answer to the problem. Explaining it will expose the full depth of my ignorance, but is the least I can do for all those that offered help. I will read the tutorial:

    http://www.utdallas.edu/~gustavo.litovsky/Tutorialv0_2.pdf

    So, I was using notes from a Electrical Engineering class on the MSP430 and I followed the notes exactly, which specify setting the Debugger to Simulator. I found that last night, however, after changing the Debugger to FET, I did not see the option to use the parallel link to load the program, which caused another cryptic problem message from IAR. I just found that and selected Olimex parallel port. Now I get a decent square wave on P5.1

    Thanks!

     

  • Steve Pitts said:
    Explaining it will expose the full depth of my ignorance

    You're not the first one stepping into the 'emulator' pit. While the emulator is a nice thing, it is not really the expected default behaviour of the debugger.
    Especially since TI decided to name their programming interfaces 'flash emulation tool' (FET)

**Attention** This is a public forum