cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to trigger an interrupt that fires a different method from a UART IRQ?

magene
Senior II

I got some excellent advice on a previous question and have a new related question. I have a app that needs to run a control loop at a specific rate with something like a few percent jitter. For example, if the control loop is supposed to run every 0.01 seconds, it should run every 0.01 seconds plus or minus a 100 microseconds or so (maybe 200-300 microseconds). The control loop starts by querying a transducer for a pressure measurement over a UART. The response time of the instrument has near zero jitter so that isn't an issue. I receive the characters from the transducer in a UART IRQ and the message is terminated with a CR. As soon as I get the CR, I'd like to send the new value to the control loop calculation method. I can call the calculation method from the IRQ but that means the IRQ has to wait for the calculation method to finish before the IRQ finishes which doesn't seem like a good idea. Is there a way for the IRQ code to just trigger an IRQ which does the control loop calculation without having to wait for the calculation to finish?

2 REPLIES 2

As I recall you can generate an EXTI or flag a lower priority interrupt in the NVIC itself

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

Brilliant, at least on your part. It didn't take me long to go from your comment to the fact that since the class that has the control loop calculation method uses a timer, I can set an unused interrupt in that timer to trigger an IRQ that runs the control loop calculation without blocking the UART IRQ.

That's the good news. The bad news is that now that I've implemented this and it seems to work, I realize that all I've done is push the blocking action of doing the control loop calculation from the UART IRQ into the TIMER_TRIGGER IRQ. Still probably a bad practice. Oh well, another seemingly good idea on my part down the tubes.

If case this approach might help someone else, here is what I did:

I put this in the UART RXIdleCallback IRQ (which is where the pressure message gets handled):

HAL_TIM_GenerateEvent(&hBE_CTDTimer, TIM_EVENTSOURCE_TRIGGER);

and this in my timer IRQHandler

if (__HAL_TIM_GET_FLAG(&hBE_CTDTimer, TIM_FLAG_TRIGGER))
{
	timer2HAL_TIMEx_TriggerCallback(&hBE_CTDTimer);
	__HAL_UART_CLEAR_IDLEFLAG(&hUART7); 
}