AnsweredAssumed Answered

Method for UART variable length receive

Question asked by Karl Fraasch on Jul 26, 2019
Latest reply on Jul 29, 2019 by Jorge Antonio Alcala Vazquez

I have been investigating different UART receive methods provided by LPUART driver in order to receive a variable length UART packet. The assumption is each UART packet will contain a fixed length header which specifies the length of the remaining packet.

 

Packet Structure

| Byte 0       | Byte 1          | Byte 2          | Byte 3  | Byte n      | Byte 3+Length-1|

| Start Byte | Length MSB | Length LSB | Data[0] | Data[n-3] | Data[Length-1]   |

 

Firmware Operation

1. Prepare receive of header size (3 bytes)

2. Receive interrupt, read out the length

3. Prepare a second receive using the length in header

4. Receive interrupt after full length has been received

 

The methods I have tried are,

Nonblocking Interrupt

Nonblocking interrupt w/ Ring buffer

Non blocking DMA

 

I have had success with the three above methods at 921600 baud rate. I am able to trigger an interrupt after the header is received and register the second receive in time to receive all bytes in the remaining packet.

 

My question is, are there any recommended methods for how best to do this? I am concerned once other interrupts and peripherals are introduced into the system, I handle the header receive interrupt before the remaining packet byte come in.

Outcomes