title: FRDM K82f uart interrupt only fires about 8 times
body: <p>I am currently having trouble getting the LPUART interrupt to work properly on the <a href="https://www.nxp.com/products/processors-and-microcontrollers/arm-based-processors-and-mcus/kinetis-cortex-m-mcus/k-seriesperformancem4/k8x-secure/freedom-development-platform-for-kinetis-k82-k81-and-k80-mcus:FRDM-K82F" rel="nofollow noreferrer">NXP FRDM K82f board</a> with <a href="https://www.nxp.com/support/developer-resources/software-development-tools/mcuxpresso-software-and-tools/mcuxpresso-integrated-development-environment-ide:MCUXpresso-IDE" rel="nofollow noreferrer">MCUXpresso IDE</a> using <a href="https://www.nxp.com/support/developer-resources/software-development-tools/mcuxpresso-software-and-tools/mcuxpresso-software-development-kit-sdk:MCUXpresso-SDK" rel="nofollow noreferrer">MCUXpresso SDK</a>.</p>
  
  <p>The LPUART interrupt only fires 6-8 times and never again after that.
  This behavior is independent from the current position in the code. I tested it by sending the first batch of data long after the program enters the infinite loop and also by sending it right at the start of the program (after lpuart interrupt initialization). Same behavior in both cases. </p>
  
  <p>This is my initialization routine and the interrupt handler.</p>
  
  <pre><code>#include &lt;stdint.h&gt;
  #include "fsl_lpuart.h"
  
  #define OSCERCLK_SOURCE 2U
  #define ESP_UART LPUART0
  #define UART_IRQ LPUART0_IRQn
  #define UART_RECEIVE_INTERRUPT LPUART0_IRQHandler
  #define BUFFER_SIZE 2048
  
  volatile uint8_t ringBuffer[BUFFER_SIZE] = {0x00};
  volatile uint16_t rxIndex = 0;
  volatile uint16_t txIndex = 0;
  
  
  void init(uint32_t baudRate){
      lpuart_config_t config;
      CLOCK_SetLpuartClock(OSCERCLK_SOURCE);
      LPUART_GetDefaultConfig(&amp;config);
      config.baudRate_Bps = baudRate;
      config.enableRx = true;
      config.enableTx = true;
      uint32_t clockFrequency = CLOCK_GetFreq(kCLOCK_Osc0ErClk);
      LPUART_Init(ESP_UART, &amp;config, clockFrequency);
      LPUART_EnableInterrupts(ESP_UART, kLPUART_RxDataRegFullInterruptEnable);
      EnableIRQ(UART_IRQ);
  }
  
  void UART_RECEIVE_INTERRUPT(void){
      uint8_t data;
      uint32_t flags = kLPUART_RxDataRegFullFlag &amp; LPUART_GetStatusFlags(ESP_UART);
      if (flags){
          data = LPUART_ReadByte(ESP_UART);
          if((rxIndex + 1) % BUFFER_SIZE != txIndex){
              ringBuffer[rxIndex] = data;
              rxIndex++;
              rxIndex %= BUFFER_SIZE;
          }
      }
  }
  </code></pre>
  
  <p>Has anybody encountered a similar behavior and is able to help?</p>
  
  <p>EDIT: 
  As @Lundin suggested I corrected the non-standard gcc syntax.
  No success yet, but I was able to track what flags are set when the ISR doesn't fire anymore.
  The set flags are:</p>
  
  <pre><code>kLPUART_TxDataRegEmptyFlag, 
  kLPUART_IdleLineFlag, 
  kLPUART_RxOverrunFlag, 
  kLPUART_RxFifoEmptyFlag
  </code></pre>
  
  <p>This looks ambiguous to me, because RX FIFO is empty and also RX is overrun.</p>