cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 usart interrupt - necessary?

Jerry Hancock
Associate II

I'm struggling with adding usart interrupts to my code. My rotary encoder uses interrupts and the touch screen keypad is polled. I'm not transferring a huge amount of data, just records of about 20 characters at the most. Today instead of interrupts I am test read 4 characters and if they are there, I fill the remaining buffer with the message and process it.

So given that I can read and process the data quickly enough to not hang up the encoder or the soft keypad, should I even bother with usart interrupts given the usart interrupt code is so basic anyway?

It would be nice if there was an interrupt driven function that captured the entire message (they are terminated by a character) and then set a flag so the mainline could process the message. Or an something I could pole from the mainline to see if data is available (can't believe there isn't a soft test of this) ? I guess I could do both with the interrupt code but I am struggling with the value as I would still want to process the message in the mainline.

Thanks

Jerry

5 REPLIES 5

It's not about the amounts of data but whether you can poll fast enough to read out an incoming byte before the next one arrives and overwrites it (causing receiver overflow). If your main is fast enough relative to the baudrate, and if you don't intend to put the mcu to sleep in the meantime, polling the UART is just fine.

JW

Well the HAL USART Interrupt based code is definitely a goat rodeo

My personal preference is to fill/empty a ring buffer using the interrupt handler, clean and simple, allows the main line application to send data to the buffer, and not wait around for the send to complete, and for input, the routines can check for user interaction when convenient.

Shown simple code on the forum to process GPS NMEA sentences in the IRQ Handler, and dispatch whole lines for processing when line closure is detected.

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

Clive, I went looking for your code, found some GPS related, but it didn't look interrupt driven. Is it still up?

Thanks to both for replying.

Jerry

This was the L4 example, the forum transition broke the formatting.

https://community.st.com/s/feed/0D50X00009XkVxKSAV

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

It almost seems like HAL or the hardware is buffering the receive. It seems like I always have data waiting, valid data that is, and I would have thought I would be dropping characters without any kind of flow control but I'm not. Granted these processors are fast and I'm only using 19.2kbps so that is running at a snail's pace. I wouldn't mind taking the entire receive routine out of the mainline. What I need are simple instructions on how to setup the interrupts considering this code was generated a while ago with cubemx and I cant regen it. I use the LTDC and USB code as well as interrupts for my encoder (2 lines with interrupts) so I have to be careful with the interrupts for usart6.

I think there is one interrupt called for both TX and RX and I have to enable the interrupt for usart6. Do I need callback routines? Is there a doc on this?

Thanks for the GPS code, I understand it and appreciate it but I need the interrupt templates.

Jerry