cancel
Showing results for 
Search instead for 
Did you mean: 

Handle Variable Length Transmission over Uart

Liferafter
Associate III

Hi!

I am somewhat unclear on how to handle variable length transmissions using the STM32F4xx HAL. I have looked at other solutions, and suggestions have been made to use HAL_UARTEx_ReceiveToIdle_DMA() or the ISR equivalent.

My situation however, involves a continuous non stopping transmission from a NEOM8N GPS Module. The GPS has a default baud rate of 9600, which I have observed in my code. It uses the NMEA0183 protocol, which has a max sentence length of 83 characters.

 

Any suggestions on how to implement the receive function for this GPS?

13 REPLIES 13
Pavel A.
Evangelist III

 The STM32 only reads the start and stop for bytes adds them to the buffer, until buffer size (max Nmea sentence length) is reached.

No this is not STM32. This is the little poor "HAL library", suitable for quick bring-up tests and reference but not for production code. STM32 hardware itself is great, it supports continuous RX with DMA or interrupts - the latter is trivial at 9600 and simpler than DMA. Just do the proper code.

 

Will do thank you for your help!

See this link which explains how to work with variable length data using HAL_UARTEx_ReceiveToIdle_DMA

https://github.com/karlyamashita/Nucleo-G431RB_Three_UART/wiki

 

 

I Can't Believe It's Not Butter. If you find my answers useful, click the accept button so that way others can see the solution.

Well the interrupt into a ring buffer works, it is preferable to do the parsing outside of the handler, as doing a lot of math and processing can be time consuming.

One could use a circular DMA buffer, acting like the HW FIFO from earlier systems, which gets swept periodically, I do that rather than this idle stuff.The parser drops through quickly if there's insufficient data to close out a NMEA Sentence.

UBX Packets have length information in the header.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..