USART Framing error flag | Improvements

What could be included in further releases, or for the forum.
Post Reply
User avatar
mikikg
Posts: 14
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

USART Framing error flag | Improvements

Post by mikikg » Sun Sep 17, 2017 6:42 am

Hi there,

as I didn't find any topic regarding USART Framing Error, here is one suggestion for future release of USART library.

Problem:
In some applications it is possible to have undefined state (not defined by external pull up/down resistor) during reset on USART TX pins.
This can cause that after reset when we define stabile state for TX pins to produce "edge" which can trigger other connected device to interpret that as START bit of serial communication.
As consequence, receiving device will have non valid data in it's receiving data register (USARTx->DR).
STM32 is smart enough to detect this as error if STOP bit not received in required time frame and will set Framing Error Flag in Status Register (USARTx->SR, USART_SR_FE).

Solution:
To prevent false triggering, it is advised to observe USART_SR_FE flag and discard that data.
So when we call for example library function Serial1.available(), function will not return TRUE if we have Framing Error, we don't want such data anyway.

User avatar
mikikg
Posts: 14
Joined: Tue Mar 07, 2017 4:08 pm
Location: Serbia
Contact:

Re: USART Framing error flag | Improvements

Post by mikikg » Sun Sep 17, 2017 6:59 am

Another improvement also regards USART.
I don't know does it used in current library, but this option will save you time and simplify program.

When receiving data via USART, it is helpful to enable IDLE interrupt which will be activated by HW if on RX line there is no more data to receive longer than time of one byte. This event can be used as "end of packet" and trigger our other functions which process received data.

With use of IDLE flag, it it much simpler to code receiving function with variable data length and without any (if we want) packet termination characters. It is useful for both ASCII and RAW/HEX serial communication.

Of course, this is applicable for data which are transferred in continuous stream of characters and without any delay (delay smaller than time of one byte) between two consecutive characters/bytes.

User avatar
Pito
Posts: 1600
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: USART Framing error flag | Improvements

Post by Pito » Sun Sep 17, 2017 9:42 am

+1
Pukao Hats Cleaning Services Ltd.

Post Reply