AnsweredAssumed Answered

Receiving multiple bytes with LPUART0 interrupt

Question asked by Jing Yin Wong on Apr 11, 2018
Latest reply on Mar 4, 2019 by Jing Yin Wong

Hi NXP Team,


I am developing an application that is able to receive multiple bytes with variable length randomly through LPUART0. I modified the LPUART sample code as follows. Baud rate is 115200 with interrupt enabled.


void LPUART0_RxTx_IRQHandler (void) {
   uint8_t recieve;

   /* Clear interrupt flag */
   LPUART0->STAT = LPUART0->STAT | 0x40000000;
   /* Wait for received buffer to be full */
   recieve= LPUART0->DATA; /* Read received data*/



int main(void) {


   /* Configure PTC2 and PTC3 as LPUART0 RX and TX */

   PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);


   INT_SYS_SetPriority(LPUART0_RxTx_IRQn, 10U);


   PCC->PCCn[PCC_LPUART0_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */
   PCC->PCCn[PCC_LPUART0_INDEX] |= PCC_PCCn_PCS(0b001) /* Clock Src= 1 (SOSCDIV2_CLK) */
   | PCC_PCCn_CGC_MASK; /* Enable clock for LPUART1 regs */
   LPUART0->BAUD = 0x16000003;

   LPUART0->CTRL=0x02C0000; /* Enable receive interrupt */



      /* Wait for the receive interrupt to get triggered */




I found that the interrupt could be triggered but I couldn't receive the right number of bytes with such implementation. For example, if 6 bytes were sent, I could only receive 2 bytes. That means "LPUART0_RxTx_IRQHandler" triggered 2 times continuously.


The API code (LPUART_DRV_ReceiveDataBlocking) was able to receive all the data sent but it requires a fix buffer size as an input parameter. Also, as the timing of receiving the data is random, I could not simply call "LPUART_DRV_ReceiveDataBlocking" function in my program and I have to write another function with interrupt enabled.


Please advice on how to receive multiple bytes (register settings etc.) with LPUART0 interrupt enabled. For example,


void LPUART0_RxTx_IRQHandler (void) {

   /* receive 1st byte */

   first_byte = LPUART0->DATA;   

   if (first_byte == 1) {

      /* receive the remaining 1 bytes */

   } else if (first_byte == 2) {

      /* receive the remaining 2 bytes */



Thank you.


Best regards,

Jing Yin