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.

multiple interrupt programming in same port

can i write two ISR,s for the same port? i need to use both the pushbuttons in P1.0 ans P1.1 to produce different time delay for blinking an LED in the P2.1

  • You can catch both triggers, but you only get a single ISR. Your ISR needs to sort out which pin(s) got you there -- P1IFG will tell you.

  • thank you for your response sir.

    but, then, how the second interrupt is executed while the first one is executing?

    i need to get the response of second switch at the time of interrupt itself..

  • NIMIN THOMAS said:
    but, then, how the second interrupt is executed while the first one is executing?

    ISR shall be processing IRQ event and incoming data (if any) as quickly as possible and finish as soon as possible. Things that is not IRQ processing like LED flashing shall be executed outside of ISR code.

  • Also, as soon as you mention (physical) pushbuttons, you need to be thinking about debouncing (search this forum, or the Web, for discussions of this), which changes your timescale from microseconds to (10s of) milliseconds. Some debouncing procedures don't involve (pin) interrupts at all.

  • NIMIN THOMAS said:
    but, then, how the second interrupt is executed while the first one is executing?

    Not at all. You only have once CPU core and it can only execute one instruction simultaneously. To execute the second interrupt, you would have to interrupt the execution of the first one. For several reasons not recommended.
    However, once you are in your ISR, the port's IFG register is available to you and you can see all pending IFG bits at the same time.
    It is, however, recommended to use the port's IV register instead, as read access to the IFG register (and worse, write access to it) may prevent a new interrupt to be recognized (racing condition).

    Fastest way is to loop through all pending port interrupts inside the ISR before exiting. Like this:

    while(1){
      switch (__even_in_range(P1IV, 16)){
        case 0: return;
        case 2: [...] // P1.0 interrupt
          break;
        [...]
      }
    }

    It saves you the interrupt latency and return time as well as the framing time (saving of registers etc.)
    The P1IV/P2IV register is only available for 5x/6x family. A replacement for odler MSP families could be done like this:

    while (P1IFG) {
      if(P1IFG&BIT0){
        [handle P1.0 interrupt]
         P1IFT &= ~ BIT0;
      }
      if(P1IFG&BIT1) {
      [...]
    }
  • Thank you all. Now i found out the problem with my code. I have executed the whole led delay in the ISR itself. Now I modified the code using an 'if' and set a manual flag which is executed in the main program. And, I have considered the debouncing delay too. Thank you all for your support..

**Attention** This is a public forum