Receiving multiple bytes with LPUART0 interrupt

cancel
Showing results for 
Search instead for 
Did you mean: 

Receiving multiple bytes with LPUART0 interrupt

1,317 Views
Contributor I

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;
   while((LPUART0->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);
   /* 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_EnableIRQ(LPUART0_RxTx_IRQn);
   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 */

   

   for(;;){

      /* 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

0 Kudos
8 Replies

248 Views
Contributor I

liuweiliang

Please refer to the attachment named "LPUART.ZIP" that can be found in the following thread.

https://community.nxp.com/thread/463166 

Hope it helps.

Thanks and regards,

Jing Yin

0 Kudos

248 Views
Contributor I

3q very much!

I tried the link you provided.it's can work.

I want to develop based on the SDK model. In my proram ,it can send,But can't receive data by interrupt .

Do your have SDK-based project about LPUART?

0 Kudos

248 Views
Contributor I

Would you provide me with the name of the SDK model?

0 Kudos

248 Views
Contributor I

jingyinwongS32K

CAN you share your project with LPUART INTURRUPT . I have the same problem。

0 Kudos

248 Views
Contributor II

Hi Jing,

I could not make RxIsr() on UART0 work. Here is my post,

LPUART0_RxTx_IRQHandler 

Could you give me hint(s) or share some codes?

Thanks,

Kevin

0 Kudos

248 Views
Contributor I

Hi Kevin,

Would you try the following?

1. 

void LPUART0_NVIC_init_IRQs(void)
{
S32_NVIC->ICPR[1] = 1 << (31 % 32); /* IRQ31: clr any pending IRQ*/
S32_NVIC->ISER[1] = 1 << (31 % 32); /* IRQ31: enable IRQ */
S32_NVIC->IP[31] = 0xA; /* IRQ31: priority 10 of 0-15*/

}

Change "ICPR[1]" to "ICPR[0]" and "ISER[1]" to "ISER[0]".

pastedImage_1.png

2. LPUART0 control register setting for your reference.

LPUART0->CTRL=0x002C0000;

Hope this helps.

Thanks and regards,

Jing Yin

0 Kudos

248 Views
Contributor II

Hi Jing Yin,

Your suggestions work!!

Thanks,

Kevin

On Fri, Feb 15, 2019 at 11:07 AM jingyinwong <admin@community.nxp.com>

0 Kudos

248 Views
NXP TechSupport
NXP TechSupport

Hi,
Could you check error flags like STAT[OR] Receiver Overrun Flag.
Have you considered using FIFO (FIFO[RXFE]). The interrupt is then called when a certain number of datawords (specified in WATER[RXWATER]) has been already received.
Unfortunately, we don’t have any example for this use case.

Regards,
Daniel

0 Kudos