Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 4 months ago.
serial TX blocks thread. How avoid it ?
Hi, forks While LED blinking by thread, the load of serial TX influences LED timing. I think Serial TX action inhibits the system timer interrupt for a long time. Or, priority of interrupt make it overrides. The influence is more large for Slow speed TX baudrate. Even, Rawserial makes same phenomena. And, TX buffer flushing is not enough for high baud rate. It left some characters. Is there some problem in Serial TX handling ? Is it thread-safe ? I doubt it is not safe.... I wanna exchange the view. Thank you.
Question relating to:
1 Answer
9 years, 4 months ago.
Yes, serial transmits will block until there is sufficient space in the Tx buffer for the remaining message. The Tx buffer will normally be 1 or 16 bytes depending on the hardware.
If you want to avoid this then you can use something like MODSERIAL ( https://developer.mbed.org/users/Sissors/code/MODSERIAL/ )
It implements a software buffer on both the serial receive and transmit and uses the serial interrupts to move data to/from the hardware buffers. Set the buffer sizes to be the largest message you expect to see plus a few bytes and it should fix the problem. It should be a drop in replacement for the mbed Serial class.