UART Communication: How to Detect if Parity is Working - Page 1
Forum section: electronics / general

author: EVblog1
author_rank: Contributor
timestamp: June 23, 2025, 11:16:46 am
content: Hi, I have a question.I’m able to send and receive data between my 8051 MCU and laptop. But now I want to understand how to test if parity settings are actually working.If I enable parity in my UART settings, how can we verify that it is being applied correctly and that parity errors are detected properly during communication?

author: Sorama
author_rank: Frequent Contributor
timestamp: June 23, 2025, 11:21:48 am
content: A scope with decoding functionality can tell you that.You could also trigger for parity errors.

author: RoGeorge
author_rank: Super Contributor
timestamp: June 23, 2025, 12:58:01 pm
content: Set the transmitter and receiver with same settings except parity. Set one side with parity odd, the other side with parity even, and you should have parity errors at each and every byte.Then, set both ends with the same parity, either odd or even, and you should have no errors.

author: NorthGuy
author_rank: Super Contributor
timestamp: June 23, 2025, 02:47:56 pm
content: Just send a byte with a wrong parity and observe the results.Correct parity is not a guarantee that the byte received is correct, and vice versa incorrect parity does not necessarily mean that the byte was transmitted wrong. Therefore, to ensure data integrity you need to use something more robust, such as CRC. But if you decide to use CRC, this will make parity checks redundant.In most cases your UART will be error free between the MCU and converter. If you do get errors, you need to figure out why and fix that. If the cost of an error is small you can drop error checking at all. If the cost of error is very high (e.g. your device will stop working), you need to use a protocol with robust error detection, re-transmissions and all that.

author: westfw
author_rank: Super Contributor
timestamp: June 24, 2025, 10:23:41 pm
content: QuoteWell, first you have to have a definition for what "detected properly" means in your particular system.AFAIK, parity on UARTs is essentially useless because it's never been clearly defined what it is you ought to do if you receive a character is received with the incorrect parity...Discarding the character is probably not useful (maybe if you have "printed" output, you'll get missing characters instead of bad characters, which is ... not much of an improvement.Ignoring the error is "popular." but ... why bother checking, if that's what you're going to do.In some sort of higher-level protocol, I supposed you could discard a whole block or packet if there was any bad parity character within it. But those tend to have their own error checking checksum or CRC.

author: Siwastaja
author_rank: Super Contributor
timestamp: June 25, 2025, 08:34:28 am
content: Quote from: westfw on June 24, 2025, 10:23:41 pmThis boils down to: it is useful to checksum fullblocksof something - whatever that is, depends on the application. Then, a full block can be ignored (in case sender sends it periodically again anyway), or re-requested.If you just check part(s) of the block separately - e.g., single bytes of multi-byte message -, it's going to be much more difficult - you then need to propagate those errors forward, to be able to deal with it at block (packet) level. In which case you could have just used one packet-wide checksum instead.Therefore, I would only see the parity bit useful in the marginal case where packet size = 1 byte. Some very simple status-command protocol could be like this: think about a product which does nothing else but output analog-to-digital converted temperature value in 7-bit binary, say between 0 - 100 degrees Celsius. And then it could have commands like turn heater on, turn heater off - which could be single bytes. In such case, each byteisthe packet, the UART peripheral itself manages the delimitation of said "packets", and, consequently, the parity bit covers the whole packet, and it is obvious to just ignore erroneous packets and the full message does not break, like it does if you ignore a single byte out of a longer packet.