cancel
Showing results for 
Search instead for 
Did you mean: 

Is USART blocks the uC during sending datas?

jean_prieur
Associate III
Posted on November 26, 2013 at 12:06

Hello,

I have a question just for my culture, I have no real error. I send datas via USART3 at the baudrate31250,USART_HardwareFlowControl_None,USART_WordLength_8b. So one USART message takes 250us to be send.Is the uC blocked during this time, or this action is achieve in parralel ? It can be a lot of time... I use this code to send USART:

while
(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
USART_SendData(USART3, data);

8 REPLIES 8
frankmeyer9
Associate II
Posted on November 26, 2013 at 12:59

You can read the reference manual to get a detailed idea how peripherals (and also the UART) work.

And no, the peripheral isn't blocking the core.

Only the code example you provided does.

John F.
Senior
Posted on November 26, 2013 at 13:32

If you want to read the manual ... have a look at how the DMA and USARTs can work together. For example, you can configure the USART to request DMA transfers when transmitting so, provided you know how many buffered bytes to send, the operation completes automatically without microcontroller help.

Another way is to use an interrupt routine that loads new data into the USART when it is ready. No DMA involved, just one interrupt to load each new data byte.

Read up on the USART flags and experiment.

jean_prieur
Associate III
Posted on November 26, 2013 at 15:07

Ok thank you. Because my USART messages have to be sent with the maximum real time, I have to choose the solution with the minimum delay.

emalund
Associate III
Posted on November 26, 2013 at 15:25

Is USART blocks the uC during sending datas?

YES, unless it is interrupt driven

some UART 'implementations' (note the quotes) employ wait loops in the main flow.

Erik
Posted on November 26, 2013 at 16:00

Use a buffer, buffer your output strings, send bytes on TXE interrupt.

If you generate data at a rate faster than the transport method, you'll need to speed up the transport, reduce your data generation, or pick another method. ie SWV

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jean_prieur
Associate III
Posted on November 27, 2013 at 18:21

Is there a way to send datas via USART and, in parallel, continue to process my other tasks ?

I mean, between the change of state of the USART output, the microcontroller can be able to do something else ?

(I program a real time system, USART datas have to be sent without delay, and others task have to be executed at the right time).
Posted on November 27, 2013 at 18:40

Is there a way to send datas via USART and, in parallel, continue to process my other tasks?

Of course there is, it's a peripheral device, and doesn't preclude you doing other things. Clearly if you sit in a loop polling it, then things will block, but that's not how people handle peripheral devices in a real-time system.

Use a ring-buffer, shovel your data in that, and service it in a USART interrupt ''task''.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jean_prieur
Associate III
Posted on November 28, 2013 at 11:21

Ok thanks, now I understand ! I'm gonna try this solution...