I am currently having trouble getting the LPUART interrupt to work properly on the NXP FRDM K82f board with MCUXpresso IDE using MCUXpresso SDK.
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.
This is my initialization routine and the interrupt handler.
#include <stdint.h>
#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(&config);
config.baudRate_Bps = baudRate;
config.enableRx = true;
config.enableTx = true;
uint32_t clockFrequency = CLOCK_GetFreq(kCLOCK_Osc0ErClk);
LPUART_Init(ESP_UART, &config, clockFrequency);
LPUART_EnableInterrupts(ESP_UART, kLPUART_RxDataRegFullInterruptEnable);
EnableIRQ(UART_IRQ);
}
void UART_RECEIVE_INTERRUPT(void){
uint8_t data;
uint32_t flags = kLPUART_RxDataRegFullFlag & LPUART_GetStatusFlags(ESP_UART);
if (flags){
data = LPUART_ReadByte(ESP_UART);
if((rxIndex + 1) % BUFFER_SIZE != txIndex){
ringBuffer[rxIndex] = data;
rxIndex++;
rxIndex %= BUFFER_SIZE;
}
}
}
Has anybody encountered a similar behavior and is able to help?
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:
kLPUART_TxDataRegEmptyFlag,
kLPUART_IdleLineFlag,
kLPUART_RxOverrunFlag,
kLPUART_RxFifoEmptyFlag
This looks ambiguous to me, because RX FIFO is empty and also RX is overrun.