title: NXP LPC17xx pending interrupts
body: <p>I am facing a weird problem with the external interrupts of the LPC17xx series.</p>
  
  <p>I have an external button set to external interrupt 1, falling edge with both an internal as an external pull-up resistor (p2.11):</p>
  
  <pre><code>PinCfg.Funcnum = 1;
  PinCfg.OpenDrain = 0;
  PinCfg.Pinmode = PINSEL_PINMODE_PULLUP;
  PinCfg.Pinnum = 11;
  PinCfg.Portnum = 2;
  PINSEL_ConfigPin(&amp;PinCfg);
  GPIO_SetDir(2,((uint32_t)1&lt;&lt;11),0);
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>EXTICfg.EXTI_Line = EXTI_EINT1;
  EXTICfg.EXTI_Mode = EXTI_MODE_EDGE_SENSITIVE;
  EXTICfg.EXTI_polarity = EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE;
  EXTI_Config(&amp;EXTICfg);
  EXTI_ClearEXTIFlag(EXTI_EINT1);
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>NVIC_SetPriority(EINT1_IRQn,1);
  NVIC_EnableIRQ(EINT1_IRQn);
  </code></pre>
  
  <p>This is a part of the ISR (including 200ms button debouncing timer):</p>
  
  <pre><code>void EINT1_IRQHandler(void)
  {
      EXTI_ClearEXTIFlag(1);
  
      uint32_t tim1Cnt = LPC_TIM1-&gt;TC;
  
      if (tim1Cnt &gt; ButtDebounceUs)
      {
          LPC_TIM1-&gt;TC = 0x00000000;
  
          // Do work here
      }
  }
  </code></pre>
  
  <p>The "Do work here" section could take some time (e.g. more than 200ms in some cases). This is intended and no problem for the further execution of the program.</p>
  
  <p>The problem is that when the ISR is entered first and I press the button a second time while the ISR is executing (this has to be done fast) a pending interrupt is set and causes the ISR to execute again if it has ended for the first time. This is normal behaviour I guess, since EXTI_ClearEXTIFlag(1) does not clear any pending interrupts in the NVIC. So I added NVIC_ClearPendingIRQ(EINT1_IRQn) to clear the new pending interrupts on several locations in the ISR code to be sure the pending interrupt(s) is/are cleared. Strangely enough this does not work at all.</p>
  
  <p>Some my question is, how can I read the pending interrupts via JTAG/debugger (memory address?). And what is going on here? Can someone explain this behaviour and maybe has a clue how to fix it?</p>
  
  <p>Thanks!</p>