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.

MSP430F5529 interrupt example not working

Other Parts Discussed in Thread: MSP430F5529

I am using the MSP430F5529-exp launchpad and code composer V6 to create some code.


I want to use P1.4 as an interrupt and I thought I would start with one of the examples from Slac300i.  The example is MSP430F55XX_P1_03.

I loaded the code into code composer and ran it.  It compiled and I was able to enter debug mode but nothing happened.  The LED does not do anything.  So I added a printf functionality to the the code to see what is happening.

The end result shows the interrupt is not recognizing an hi to low edge trigger.  I am repeatable grounding the pin to create an hi-lo edge.


Here is the code I am using:

//******************************************************************************
//  MSP430TC0701 Demo - Software Port Interrupt Service on P1.4 from LPM4   -  modified by adding printf functionality
//
//  Description: A Lo/Hi transition on P1.4 will trigger P1ISR the first time.
//  On hitting the P1ISR, device exits LPM4 mode and executes section of code in
//  main() which includes toggling an LED and the P1.4IES bit which switches between
//  Lo/Hi and Hi/Lo trigger transitions to alternatively enter the P1ISR.
//  ACLK = n/a, MCLK = SMCLK = default DCO
//
//               MSP430F552x
//            -----------------
//        /|\|              XIN|-
//         | |                 |
//         --|RST          XOUT|-
//     /|\   |                 |
//      --o--|P1.4         P1.0|-->LED
//     \|/
//
//   Bhargavi Nisarga
//   Texas Instruments Inc.
//   April 2009
//   Built IAR Embedded Workbench Version: 4.11A
//******************************************************************************
#include <msp430.h>
#include <MSP430F5529.h>
#include <stdio.h>
#include <string.h>

#define UART_PRINTF

#ifdef UART_PRINTF
int fputc(int _c, register FILE *_fp);
int fputs(const char *_ptr, register FILE *_fp);
#endif

int main(void)
{

    #ifdef UART_PRINTF
      // initialize USCI module
      P4SEL |= BIT4 + BIT5;                     // P4.4,5 = USCI_A1 TXD/RXD
      UCA1CTL1 |= UCSWRST;                      // **Put state machine in reset**
      UCA1CTL1 |= UCSSEL__ACLK;                 // AMCLK
      UCA1BR0 = 3;                             // 32,768kHz 1200 (see User's Guide), original example used 27,  set to 3 for 9600
      UCA1BR1 = 0;                              // 32,768kHz 1200, original example used 0,   set to 3 for 9600
      UCA1MCTL = UCBRS_3;                       // 32,768kHz 1200
      UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    #endif


  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= BIT0;                            // Set P1.0 to output direction
  P1OUT &= ~BIT0;
  P1REN |= BIT4;                            // Enable P1.4 internal resistance
  P1OUT |= BIT4;                            // Set P1.4 as pull-Up resistance
  P1IES &= ~BIT4;                           // P1.4 Lo/Hi edge
  P1IFG &= ~BIT4;                           // P1.4 IFG cleared
  P1IE |= BIT4;                             // P1.4 interrupt enabled

  printf("P1.4 interrupt example....Hello World!\r\n");

  while(1)
  {
    printf("enter while loop.");
    __bis_SR_register(LPM4_bits + GIE);     // Enter LPM4 w/interrupt
    __no_operation();                        // For debugger
    printf("about to toggle LED.");
    P1OUT ^= BIT0;                          // P1.0 = toggle
    P1IES ^= BIT4;                          // Toggle between H-L and L-H transition triggers
    P1IE |= BIT4;                           // Enable port interrupt
  }
}

// Port 1 interrupt service routine
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(PORT1_VECTOR))) Port_1 (void)
#else
#error Compiler not supported!
#endif
{
  P1IFG &= ~BIT4;                         // Clear P1.4 IFG
  P1IE &= ~ BIT4;                         // Clear P1.4 IE
  printf("p1.4 was triggered!\r\n");
  __bic_SR_register_on_exit(LPM4_bits);   // Exit LPM4
}

#ifdef UART_PRINTF
int fputc(int _c, register FILE *_fp)
{
  while(!(UCA1IFG&UCTXIFG));
  UCA1TXBUF = (unsigned char) _c;

  return((unsigned char)_c);
}

int fputs(const char *_ptr, register FILE *_fp)
{
  unsigned int i, len;

  len = strlen(_ptr);

  for(i=0 ; i<len ; i++)
  {
    while(!(UCA1IFG&UCTXIFG));
    UCA1TXBUF = (unsigned char) _ptr[i];
  }

  return len;
}
#endif

----------

The output of the printf on the serial port is the following:

P1.4 interrupt example....Hello World!
enter while loop.

--------

So,  why does this example not work ?  It should be a clean piece of code since it is an example.  :)

How do I troubleshoot an interrupt issue? 

Repeatedly grounding the P1.4 pin to create an edge transition is not working. 

Also, when I put 3.3V on P1.4  the system crashes.

Any help would be great.

Chris

  • Hi Chris, 

    Looking at the description of the code in the comments at the top of the file, it looks like "A Lo/Hi transition on P1.4 will trigger P1ISR the first time." Then, "main() which includes toggling an LED and the P1.4IES bit which switches between Lo/Hi and Hi/Lo trigger transitions to alternatively enter the P1ISR." 

    So it looks like you need to first do a Lo-->Hi transition on the pin, then it will alternate between the two transition types. If you're presenting it with only Hi-->Lo transitions its not going into the ISR.

    Best regards, 
    Caleb Overbay

  • When I do that...CCS crashes....besides the code clear states that   P1IES &= ~BIT4;             which sets P1.4 Lo/Hi edge.

    This is the example code from TI.  Did you attempt to run this?  Please try it out.

  • Hi

    it is possible "printf" is "too big" for being called within interrupt? Try to set a flag there, check the flag in the main code, and printf if the flag is set.
  • Hi Chris,

    You're right, the code is first setup to react to a Lo-->Hi transition. You previously stated you were performing a HI-->Lo transition and nothing was happening.

    Also, you typically don't want to call function within an ISR. I would suggest removing the printf and setting a breakpoint instead to see if the ISR is entered.

    Best regards,
    Caleb Overbay
  • Hi Chris,

    I also tried running the example myself and did not experience the issue you are seeing. Did removing the printf have any affect?

    Best regards,
    Caleb Overbay

**Attention** This is a public forum