Skip to main content
CYara.1
Associate II
October 19, 2021
Solved

UART Interrupt dosen't cause lag ?

  • October 19, 2021
  • 4 replies
  • 1148 views

I run an example project which has 250 ms HAL_Delay with led blinking in while loop, and also an HAL_UART_Transmit_IT function which prints "Hello world!" with HAL_UART_TxCpltCallback calling itself.

250 ms led blink is not lagging and printing also works.

Quesition is; since interrupt also requires CPU, why led blinking is not lagging ?

Doesn't the interrupt just change the flow of the code which will be executed by the CPU?

This topic has been closed for replies.
Best answer by Peter BENSCH

Well, the question is, how you define "blocking".

The interrupt method always gets the next character via interrupt, which only takes a few clock cycles that can normally be neglected, but of course you could measure it.

In contrast to this, the polling always waits until the characters have been transmitted, which logically slows down the CPU.

4 replies

Peter BENSCH
Technical Moderator
October 19, 2021

Welcome, @Cüneyt Yaran​, to the community!

What lag do you expect?

The HAL_Delay blocks the CPU while waiting for the end of the delay, but HAL_UART_Transmit_IT will not visibly lag this while transmitting the few characters, at best you might be able to measure it.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
CYara.1
CYara.1Author
Associate II
October 19, 2021

Hello, thank you for answer @Peter BENSCH​  

i print 2000 character. actually im doing this example;

https://youtu.be/ic7hCrDopOQ?t=474

and it says interrupt method, data transfers are non-blocking.

Peter BENSCH
Peter BENSCHBest answer
Technical Moderator
October 19, 2021

Well, the question is, how you define "blocking".

The interrupt method always gets the next character via interrupt, which only takes a few clock cycles that can normally be neglected, but of course you could measure it.

In contrast to this, the polling always waits until the characters have been transmitted, which logically slows down the CPU.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Oliver Sedlacek
Senior
October 19, 2021

The delay function uses a hardware timer (usually Systick but not always) and counts overflow interrupts until the number of interrupts calculated as corresponding to 250 msec have occurred. When the CPU has other work to do, e.g. servicing the print spool USART interrupt, the timer will still be counting. You only get a problem if the servicing of the timer interrupt is blocked by a higher priority interrupt service routine for longer than the timer overflow period.