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.

NMI won't work in my code or example code

Other Parts Discussed in Thread: MSP430G2452

I've configured the RST/NMI pin to be a non-maskable interrupt.

The voltage on the RST/NMI pin is pulled down when I press switch S2, but the interrupt never occurs. I have set NMIIE.

Here is the example code which is pretty much the same thing I tried to implement in my code. Neither work.

Any ideas?

Thanks

//******************************************************************************
//  MSP430G2xx2 Demo - Basic Clock, Configure RST/NMI as NMI
//
//  Description: Configure RST/NMI as NMI, hi/lo edge. Flash P1.0  inside of
//  NMI_ISR if NMI occurs. General enable interrupt in status register does
//  not need to be set for NMI. NMIIE does need to be reset, as NMI_ISR
//  automatically clears NMI enable to prevent unintentional stack overflow
//  that could result from, bounce or uncontrolled NMI's.
//  ACLK = n/a, MCLK = SMCLK = DCO ~ 800k
//
//               MSP430G2xx2
//            -----------------
//        /|\|              XIN|-
//         | |                 |
//         --|RST          XOUT|-
//           |                 |
//
//  D. Dang
//  Texas Instruments Inc.
//  December 2010
//  Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include  <msp430g2452.h>

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD + WDTNMI + WDTNMIES;  // WDT off NMI hi/lo
  P1DIR |= 0x01;                            // Set P1.0 to output direction
  P1OUT &= ~0x01;                           // Clear P1.0 LED off
  IE1 |= NMIIE;                             // Enable NMI

  _BIS_SR(LPM0_bits);                       // Enter LPM0
}

#pragma vector=NMI_VECTOR
__interrupt void nmi_ (void)
{
  volatile unsigned int i;
  P1OUT |= 0x01;                            // Set P1.0 LED on
  for (i = 20000; i > 0; i--);              // Delay
  P1OUT &= ~0x01;                           // Clear P1.0 LED off
  IFG1 &= ~NMIIFG;                          // Reclear NMI flag in case bounce
  IE1 |= NMIIE;                             // Enable NMI
}

  • OK, so it seems to work if I'm not using the debugger. The red LED came on if I just plugged the board in and pressed the switch, but if the program is running in the debugger then it never lights up.

    This is going to make it difficult to work on my code... I don't understand why it would happen like this.

  • Are you using the launchpad?
    Are you still in debug mode when running code?, may have to unplug RST jumper while testing.

     

    Warning:
    Only use the NMI as a last resort, and only if it can be added last in development.
    You can not debug your code once it's set.

    You can not read its current state, your interupt routine would have to set flags etc.
    And noise on a mechinical switch will trigger false low-high-low signals,
    So use a hardware debouncer like this instead of the 47k pull-up resistor.
    (R1 & R2 = 20k, C = 2nF)
     http://www.ganssle.com/images/debouncerrc.jpg

     

     


     

     

  • Steven Mills said:
    OK, so it seems to work if I'm not using the debugger.

    That is a correct behavior. You will not get the external NMI interrupt when the debugger is connected to the Target. This is because the debugger will have full control over the Target device and will effectively disable the external Reset/NMI.

    Steven Mills said:
    This is going to make it difficult to work on my code...

    On way to get the NMI interrupt while the Target is attached to the debugger, is by manually setting the NMI interrupt Flag bit in the IDE.

    Hope this helps, otherwise please let me know.

    BR,

    Mo.

**Attention** This is a public forum