2021-04-30 11:55 AM
I am using STM32CubeIDE with a STM32F103 and have UART1 setup in interrupt mode. Is there a working code example anywhere that tells how to implement UART interrupt mode? I have been unable to find via g~~gle. I have worked with multiple other processors other than STM32 and have never had a problem with UARTs. Apparently with all the posts online asking for help anything other than polling is a problem with the STM32 line.
Basically I am trying to do something really simple. I have a GPS unit that I have programmed to send the single $GPRMC message. All I want to do is read the incoming message 1 character at a time and copy it to a buffer until the '\n' character is received. I will read the character in the interrupt routine and copy it to the buffer. I will check the character in the interrupt routine for a '\n'. When that character is received I will set a flag that will be picked up in my main while loop and the string data will be processed. I have approximately 800 msecs to process the data before the next NEMA transmission starts. The baud rate is only 9600 which the STM32 UART should be able to easily process since the CPU is running at 72 MHz. The problem is the interrupt never happens. I will never transmit any data so the UART transmit function is not needed.
I saw a post that indicated user Tesla DeLorean had a working NEMA example. But apparently that code is no longer available. I have seen examples online where an echo server is implemented without using the STM32CubeIde MX environment. Is it better to do it that way and just ignore all the CubeMX mess?
Any help is appreciated.
Solved! Go to Solution.
2021-04-30 12:02 PM
https://community.st.com/s/contentdocument/0690X000008B85YQAS
2021-04-30 12:02 PM
https://community.st.com/s/contentdocument/0690X000008B85YQAS
2021-04-30 12:26 PM
Clive,
Thank you. That should help me figure the UART interrupt out.
I have already written the code for processing the NEMA sentence using a static $GPRMC sentence. My only issue is with the UART receive interrupt not firing.
2021-04-30 12:34 PM
I posted a new L4 version at some point. The F1 UART is simpler, but you do need to watch for framing and other statuses, which get cleared by reading DR
I have generally found the CubeMX/HAL gets in it's own way here, and at the end of the day each byte received has it's own interrupt. The goal here is to buffer a sentence at a time, with the ability to resync, and then dispatch the full lines to a processing routine. Typically that is better done in its own task/process where the time constraints are looser. The IRQ/Callback basically has a single byte-time window, and it's easier to manage that if the parsing and floating point math are pushed off to another task.
Also avoid 32-bit floats for latitude/longitude, at a World level they have inadequate resolution/precision
2021-04-30 02:12 PM
Thanks Clive. After making modifications to handle the differences between the STM32F746 and STM32F103, the interrupt is now working fine. I have had it running continuously now for 15 minutes. For testing purposes I am re-transmitting the NEMA incoming data out USART1 to a terminal program. So far it hasn't missed a beat. So the bottom line is "do not use CubeMX/HAL for an interrupt driven UART".
I am only extracting the time and date information as I am building a large digit 7 segment LED clock. This is just a fun project to kill time. I could have used a PIC or an AVR device but I wanted to continue the STM32 learning curve that I have been working on for the last year or so.
Again, a Big Thanks for your help!!:grinning_face: