cancel
Showing results for 
Search instead for 
Did you mean: 

UART Interrupt Issue and Interrupt Generating

ABuyu.1
Associate II

Hi, I am using UART receiver in interrupt mode. After couple of hours it stops working(Only the UART Receiver Interrupt stops working, TX and Main loop keeps working). The handler function is too big and this is probably why it happens. If I were to post the code in here you would say that I shouldn't use it like that. I can set some flags and try to make it work in main loop but the thing is I have a routine that needs to be triggered in a couple of seconds and it is not more important than uart interrupt routines.

Is there any way that I can trigger an interrupt manually and make it's interrupt priority less than UART interrupt so that it can be done after UART handler function.

If there is can you suggest me resources that I should be following

Example :

while(1)

{

Least important routine;

}

UART_Interrupt_Handler(void)

{

Parsel Data;

when complete -> Order_Flag = 1;

Restart UART interrupt reception mode

}

Order_Flag_Interrupt_Handler(void)

{

Process that needs to be done according to order.

Restart Order_Flag_Interrupt reception mode (Order_Flag = 0);

}

3 REPLIES 3

Which STM32?

Do you check and handle overflow (UART_SR.ORE)?

The usual thing to do is that in the USART interrupt only the received data are stored into a circular buffer, and this gets checked/processed/emptied in the main loop.

JW

I'm not looking to wade through broken code.

The RX could fail if you have some sort of framing, parity or overrun error that you need to explicitly clear.

Generally you'd buffer data in the UART interrupts, and leave.

I would not do extensive parsing in the handler. Doing a simple line buffer, and queuing whole lines to another task is reasonable.

You need to be in the handler for less than a byte-time.

A lower priority task/interrupt, say at 20 or 50 Hz, could then process the data. Have a clear idea of how long it takes. If it contains processing that can be deferred or queued rather than blocking.

The NVIC does allow you to define priorities, and preemption levels, and also to flag/trigger interrupts within the NVIC. Check some docs on the NVIC, and perhaps books by Joseph Yiu and others.

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

I found out that people use a timer interrupt and reload counter value to minus 1 of what is written on period register. So the timer interrupt is generated at that moment. Thank you all.

Solution for others :

while(1)

{

delayms(x);

least important routine;

}

Uart interrupt handler(void)

{

parsel data;

when completed -> Set Flag = 1; set timer counter to Period reload register - 1;

restart uart receiver interrupt;

}

Timer Interrupt Handler(void) ( Make prescaler and period so big that it doesn't get triggered again while in the handler function)

{

if(Flag = 1)

{

take the data and do the routine;

Flag = 0;

restart the timer interrupt;

}

}

Thus, at least with my timing requirements, there won't be any issue in my design.