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.

CCS/MSP430G2452: interrupt issue

Part Number: MSP430G2452

Tool/software: Code Composer Studio

Hello, 

I am new to programming microcontrollers, my issue is with interrupts. I have created two interrupts on different ports within port 1, my code follows.

My issue is that I would like to not run an interrupt if another has been executed. I am doing this with variables by giving " int variable = (variable + 1); " in the first if statement. 

How can I have the correct syntax so that I can not enter my second interrupt if a variable has not been met?

thank you!

#include <msp430.h>#define MOTOR BIT0

#define LED_M BIT6
#define BOWL BIT3
#define CONTAINER BIT4
#define LED_C BIT7

int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= (MOTOR + LED_M + LED_C); // Set P1.0 to output direction
P1OUT &= ~(MOTOR + LED_M); // set P1.0 to 0 (LED OFF)
P1IE |= (BOWL + CONTAINER); // P1.3 & P1.4 interrupt enabled
P1IFG &= ~(CONTAINER + BOWL); //P1.4 & P1.3 IFG cleared

__enable_interrupt(); // enable all interrupts
const int variable =0;

for(;;)
{


}
}

// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1_ISR(void)
{
if(P1IFG & BIT4)
//CONTAINER
{

P1OUT ^=(LED_C);
int variable = (variable + 1);
P1IFG &= ~CONTAINER; // P1.3 IFG cleared
P1IES ^= CONTAINER; // toggle the interrupt edge, the interrupt vector will be called when P1.3 goes from HitoLow as well as LowtoHigh


}
if(P1IFG & BIT3 & variable==0)
//BOWL
{
P1OUT ^= (MOTOR + LED_M); // P1.0 & P1.6 toggle
P1IFG &= ~BOWL; // P1.3 IFG cleared
P1IES ^= BOWL; // toggle the interrupt edge, the interrupt vector will be called when P1.3 goes from HitoLow as well as LowtoHigh

}}

  • Hi Tim,

    First, if you define "variable" in your main function, you will not have access to it in your ISR. You will need to make it a global variable (declare it outside of any function), and then when you change the value of it in your ISR you will not need to redefine it (no "int"). Also, could you clarify what you are trying to do logic-wise? If you get an interrupt on pin 1.4, does that mean that you don't want to process an interrupt triggered on pin 1.3, and vice versa?

    Also, instead of using a bitmask with the interrupt flag, you could make use of a switch statement as shown in pin examples found here: www.ti.com/.../getliterature.tsp

    Hope this helps,
    Nathan
  • Nathan,
    Thank you for the response. What I am attempting to do is prioritize one interrupt to not execute another when one has been flagged. I am using interrupts because the sensors I have will not detect PxIN or Pxsel to the sensitivity I am requiring for my application. To clarify, ONLY if p1.4 interrupt initiates(flags) do I NOT want to execute P1.3 until I reset the microcontroller. I am trying to add a variable that will within p1.4 that will allow me to not enter the interrupt for p1.3. I am not sure how to correctly execute this and am having trouble finding examples of this.
    Thank you
    -Tim
  • Hi Tim,

    Thank you for the clarification. Your logic looks fine, because you will enter the same ISR for any pin on port 1, and your additional variable will prevent the if statement for P1.3 from being executed if an interrupt on P1.4 has already been triggered. The only issue that I see is that you need to declare that variable as a global and update the value in your ISR (otherwise the value will be lost each time you leave the ISR). This is a general C coding issue, so MSP430 examples will not necessarily help. Please give this a try and see if it does what you are intending for it to do.

    Regards,
    Nathan
  • What NathanS said, plus:
    > if(P1IFG & BIT3 & variable==0)
    This condition is always false. You probably want
    > if((P1IFG & BIT3) && variable==0)

    From your description, a simpler method might be to disable the P1.3 IE, something like:
    if (P1IFG & CONTAINER) P1IE &= ~BOWL; // Never trigger on BOWL (P1.3) again
  • Nathan, 

    Worked great, thank you!

    -Tim

**Attention** This is a public forum