UART background oparation

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User12252
Level 1
Level 1
Hello,
I'm trying to implement serial interface with the lowest possible processor load.
Should I use DMA or Interrupts. If interrupts are the option, how do I implement handler on data receive event if there's no IRQ handler available for the user in UART DAVE APP.
There's only event on successful receive declared number of bytes, but how would I know, how many bytes to receive? I don't want to check if there's data in buffer in a loop, like it's in all exaples.
0 Likes
1 Reply
DRubeša
Employee
Employee
First solution authored First like received
Hi,

there is a plenty of ways to achieve the successful receive but none of them is optimal from a "lowest possible processor load" point of view. UART is very simple protocol that requires polling or you need to know what is number of bytes you´ll receive.

To answer your first question, you should use DMA. But you want to have full benefit of using DMA (auto increment, interrupt on received block...), so you should used UART and DMA APP. You will have some code overhead because of the DMA configuration, but in the long run you should benefit from it. If this is too much work or too complicated than you use Interrupt handling.

The basic approach would be to use receive function with number of expected data 1. Then you would enter the interrupt handler every single time once 1 byte is received. This approach however is not very effiecient (CPU needs to enter interrupt handler constantly) and you could miss a next data while you´re still processing interrupt handler. To avoid entering interrupt handler so often (meaning to lower the CPU usage), you can use FIFO buffer. Let´s say you define that interrupt occurs once the 10 bytes are received. The problem is what if you receive only 5 or 9 bytes? No interrupt will be generated and you have a problem. Still, you could miss a data while you´re processing the interrupt handler.

Now you can see, why I said that it´s very important in UART to know how many bytes you´ll receive to use some more efficient approach then polling. Most "famous" application of UART, communication with terminal, uses polling while we don´t know number of characters user will enter in the terminal.

So, as you can see there is not best answer for your question. You need to see what suits best your application.

Bets regards,
Deni
0 Likes