Parity bit in error checking

I have been trying for long time to understand what is the use of parity bit in UART. i still don't quite get it.

I found that the parity bit is used in error checking.

Suppose I am sending a byte 0101 0011 from the Arduino to the PC over Uart, what could be the error checking in this regard?

Yes.
There are two types of parity odd and even.

The parity bit is set so that the total number of one bits in the message bits is an even number, or an odd number.
If you count them up and don't find an even number then there is an error, for even parity anyway.

A parity bit is an extra bit that does not appearer in the data.
For Odd parity the extra bit would be a 1, for even parity it would be a 0.

I don't understand what kind of error is generated which is checked by parity bit

serial data can be transmitted over long distances, RS-485 over 4000ft and it would be naive to expect zero errors.

the parity bit is toggled with each 1 in the data and allows detection of an odd # of bit errors in a single byte being transmitted.

presumably a message composed of multiple bytes should be discarded if any single byte has a error. acknowledgement/retransmission allows messages to be resent on errors

there are of course much more sophisticated methods for detecting and even correcting errors in large sets of data

I still don't fully understand what the error means. When we transfer data it gets corrupted which means original data is not received, is it an error?

a parity error indicates that the "received" data is corrupted, not that it is not received.

it's up to the user of the data to decide what to do with corrupted data

1 Like

An error would be when a 1 is transmitted but a 0 is received, or a 0 is transmitted but a 1 is received. Parity can detect a single bit error, but cannot determine which bit is incorrect.
Parity goes back way farther than modern computers, at least as far back as electro-mechanical teleprinters, where the connection could be hundreds of miles over physical telephone wire, making it much more likely that something might corrupt the signal.

1 Like

how would the parity error be indicated? would the character not be printed?

I'm not really sure, I can find references to the model 33 teletype having an option to support parity checking, but have not searched enough to find what it does when the error occurs. I suspect parity errors were a lot more common when the 1's and 0's were generated by mechanical switch contacts.

Hi,
in my time as an IBM technician parity was used within the mainframe CPUs between register data ports and I/Os.
Back then circuits were less reliable than they are today.
There were separate circuits that detected parity errors and indicated that the error occurred.
But the concept of parity does not detect error if by chance the number of bits in multiples of 2 fail.
If for example 2 or 4 bits fail they will not be detected by the parity circuits.
In the UART, when you define the use of parity, the "software" that manages the reception should indicate the error, and the programmer write routines to handle this error.

Other resources can be used to detect errors in transmission, such as CRC, but they impact performance.

PS: I found this information about parity checking on arduino:

See in post#5

In the AVR core, characters with incorrect parity are thrown away and you will not see them. Framing errors are ignored so characters with a bad stop bit are received as valid. Data Overrun errors are ignored so if the interrupts are turned off for too long the characters are just lost.

1 Like

For 9600 baud, 8 bits, even parity

UART Frame START + 8 BITS + STOP

The start bit indicates start of transmission of one byte. it is always logic 0.
The stop bit indicates end of transmission of one byte. It is always logic 1.

0010 1101 How to know in which position of bit is the error?

You can't with parity, it only detects the error, cannot determine the position.

Incorrect, UART Frame would be START + 8 BITS + Parity BIT + STOP

1 Like

In legacy systems, there would often be a mechanism in the ‘protocol’ to request the data be sent ‘again’ if a parity or framing error was detected.

This was addressed to some extent by putting the data into packets, and using CRC cjecking to impose less overhead ‘per byte”, but add processing overhead per data block.

The other more advanced options are to use a more complex coding with EDC (Error Detection and Correction), but this is part of the transmission protocol, not the interface.

The ‘ED’ part usually invokes parity, framing or CRC checking of the data, and includes a ‘back channel’ to notify the sender of any error.
If the specific bit errors can be identified by the receiver, the ‘C’orrection may be applied without requesting the data ides resent.

It’s all a trade-off in serial latency, processing speed, and the cost of the serial comms link.

See these links
Parity (computing)

  • Parity bit in computing, sets the parity of data for the purpose of error detection
  • Parity flag in computing, indicates if the number of set bits is odd or even in the binary representation of the result of the last operation
  • Parity file in data processing, created in conjunction with data files and used to check data integrity and assist in data recovery

You simply don't know, all you know is that in that data then either at least one zero or at least one one (1) is incorrect.

In the control options of the UART then is a bit you can set so that parity errors are ignored and you get the data anyway or that a parity error produces no data for that transaction. There is also a bit in the status register of the UART that is set if a parity error is detected, so you can detect it and take your own action.

It is important to know that if you get multiple errors in the data, these can cancel each other out so it will only detect a one bit error.

Look at the data sheet for the ATmega328 processor and search for "UART" to see these registers and settings. Do not confuse this with the "USART" which is something difference.

A joke can often help, in this case:-
I had a friend who was having an affaire, referred to the person he was having an affaire with as "Parity", because she was a bit on the side.

There are other protocols that are known as error correcting codes, where in effect the data is bundled into three septate byte and parity is calculated on all three. If there is an error then the code with the most votes for no error is chosen. This is used a lot in digital TV systems.

Hi,
IBM developed and used an error detection system with the name ECC in main frame machines.
This hardware process, known as double bit error correction, could identify and correct up to 2 bits in a memory data read.

There are many highly sophisticated error detection and correction coding schemes nowadays. Interestingly, the extra bits (or bytes) that are added to the original message to provide the redundancy are still called "parity" bits (bytes).

In the context of ATmega328P MCU of the Arduino UNO Board:
1. A UART Frame with Odd Parity for the transmission of character 6 is shown in Fig-1.


Figure-1:

2. Odd Parity refers to the insertion/transmission of necessary 1 after the transmission of the character code so that there are odd number of 1s in the frame excluding the STAT/STOP Bits. The odd parity bit is automatically inserted when the "Parity Mode Bits (Fig-2)" of the UCSR0C Register are initialized.


Figure-2:

3. At the receiver side, the number of 1s are recomputed from the received frame (excluding the START/STOP Bits) and if the number of 1s are not found odd, then the "UPE0-bit" of UCSR0A Register is set HIGH indicating that the received frame is probably bad. However, for some reasons if there are two 1s are dropped, the frame still contains odd number of 1s; the UPE0-bit will not be set to HIGH; but, the frame is corrupted.

4. The MCU has no interrupt scheme to notify the user about the parity error; it is the job of the user program to poll the UPE0-bit to recognize the possible parity error.

5. If using Serial object, as fa as I know, there is no option to poll the UPE0-bit in order to ascertain the parity error.

6. If the receiver wants to notify the sender to re-transmit the corrupted frame, then the sketch is to be created using register level instructions with appropriate software handshaking signals.

Actually RS-232-C is SEVEN BIT system for sending ASCII. The 8255's (original UART) emulated ASR-33 (which I was trained to maintain courtesy us army 32F20). You can have EITHER 8 bit data, OR parity on 7-bit data, but NOT BOTH.
ASCII includes all sorts of machine control codes, as well as, originally, being uppercase only since ASCII was derived from 5 bit teletype BAUDOT encoding.
When an ASR-33 detects a parity error, it registers as a NUL, chatters the carriage to show a symbol was received, and dings the bell to indicate the error. A NAK is also sent in response at the message level vs an ACK if no errors found.
Now the 8255 docs aren't all that clear about the interaction between 8 bit data and parity. You can command the 8255 to 8 bits WITH parity, but it's NOT going to work. 8N1 is the only combo that actually sends 8 bit data -- without parity.
This is why you have to convert 8 bit binary data to two ASCII hexadecimal characters. But ASCII sent with character parity (detects any single bit error) and with message level ACK/NAK, sending 8 bit data is reliable, whitespace formattable, and essentially error free, albeit s-l-o-w.
If you try to send raw binary as 8-bit raw data, it's not going to work. You're going to be randomly commanding printer control functions instead of sending legitimate data. FFh is NUL, for example, which is generally ignored. Sending a long stream of NUL's (block of 1's) is generally considered a comms error.

Three. "None" as in, 9600, 8, 1, N

There is nothing such as "None" -- it is the "Disabled" option (Fig-1).


Figure-1: