[SOLVED] Even parity single-bit error

Thread Starter

MTech1

Joined Feb 15, 2023
161
I'm trying to understand concepts how does a UART receiver detects a single-bit error in a byte of data. When UART configuration is 9600 speed, 8 data bits, and even parity.

In this scenario, the original data '1010 1100' was sent, but due to an error, it became '1000 1100.'

Original Data: 1010 1100 (count of '1's is 4, an even number)

Modified Data: 1000 1100 (count of '1's is 3, an odd number)

Could someone explain that how UART receiver with even parity uses to identify single-bit errors in above example ?
 

Thread Starter

MTech1

Joined Feb 15, 2023
161
I still don't fully understand how reciver detect that byte is corrupted.

When UART configuration is 9600 speed, 8 data bits, and even parity.

Byte1 1010 1100 sent to receiver 4 1's ( orginal byte)

Byte1 1010 1110 sent to receiver 5 1's ( modified byte dute to some reason)

Byte2 1111 1111 sent to receiver 8 1's

Byte3 0000 0000 sent to receiver 0 1's

First byte is corrupted and Byte 2 and Byte3 are original byte.

What happens during operation how receiver check all these byte for error
 

MrChips

Joined Oct 2, 2009
30,488
What is the meaning of even parity?

It means that the total number of 1's in the 8 data bits and the parity bit is an even number.
The receiver counts the number of 1's in the 9 bits received. If it is an odd number then an error had occurred. Instead of counting, it can be done with cascaded XOR gates.

Single parity checking can detect a single bit error. It cannot determine which bit is in error.
It cannot detect errors occurring in two bits.
 

Thread Starter

MTech1

Joined Feb 15, 2023
161
What is the meaning of even parity?

It means that the total number of 1's in the 8 data bits and the parity bit is an even number.
The receiver counts the number of 1's in the 9 bits received. If it is an odd number then an error had occurred.
I am still confused. I can calculate number of 1s in 4 bit binary numbers and include even parity bit 1

0 (0000) - Number of 1's: 0, Number of 1's (Including Even Parity): 1
1 (0001) - Number of 1's: 1, Number of 1's (Including Even Parity): 2
2 (0010) - Number of 1's: 1, Number of 1's (Including Even Parity): 2
3 (0011) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
4 (0100) - Number of 1's: 1, Number of 1's (Including Even Parity): 2
5 (0101) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
6 (0110) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
7 (0111) - Number of 1's: 3, Number of 1's (Including Even Parity): 4
8 (1000) - Number of 1's: 1, Number of 1's (Including Even Parity): 2
9 (1001) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
10 (1010) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
11 (1011) - Number of 1's: 3, Number of 1's (Including Even Parity): 4
12 (1100) - Number of 1's: 2, Number of 1's (Including Even Parity): 3
13 (1101) - Number of 1's: 3, Number of 1's (Including Even Parity): 4
14 (1110) - Number of 1's: 3, Number of 1's (Including Even Parity): 4
15 (1111) - Number of 1's: 4, Number of 1's (Including Even Parity): 5



In this representation, "Number of 1's" indicates the count of 1's in the original four-bit binary numbers, and "Number of 1's (Including Even Parity)" indicates the count of 1's when an even parity bit of 1 is added to each binary number
 

MrChips

Joined Oct 2, 2009
30,488
No. The parity bit is not 1. The parity bit is set to 0 or 1 to make the entire data even parity.

Examples, here the parity bit is shown as (p)

(p)
(0) 0000
(1) 0001
(1) 0010
(0) 0011
(1) 0100
(0) 0101
(0) 0110
(1) 0111
 

Thread Starter

MTech1

Joined Feb 15, 2023
161
No. The parity bit is not 1. The parity bit is set to 0 or 1 to make the entire data even parity.
Hello,

Suppose we are working with a microcontroller that sends many bytes continuously to a UART device. I I'm curious about how the microcontroller decides whether it should set the parity bit to 1 or 0 when sending byte to the UART device. Could someone please explain the process or criteria that the microcontroller uses to determine the parity bit setting?

Thank you!"
 

ericgibbs

Joined Jan 29, 2010
18,651
Hi,
It is preprogrammed.

The following settings must be used in the UART terminal:
  • Baud Rate: 115200bps.
  • Parity: None.
  • Data: 8 bit.
  • Stop bits: 1 bit.
  • Flow Control: none.
E

115200,E,8,1

BaudRate,Parity,Bits,StopBits,FlowControl


Visual Basic example
MSComm1.Settings = "115200,N,8,1"
 
Last edited:

crutschow

Joined Mar 14, 2008
34,047
process or criteria that the microcontroller uses to determine the parity bit setting?
From google:
"The value of the parity bit is calculated by performing a logical exclusive OR (XOR) that combines all of the bits in the byte. This calculation is often performed in hardware by the UART, as a part of the transmission function."
 

MrChips

Joined Oct 2, 2009
30,488
Hello,

Suppose we are working with a microcontroller that sends many bytes continuously to a UART device. I I'm curious about how the microcontroller decides whether it should set the parity bit to 1 or 0 when sending byte to the UART device. Could someone please explain the process or criteria that the microcontroller uses to determine the parity bit setting?

Thank you!"
When transmitting using UART protocol, you need to decide how many data bits to send. It could be 5 to 9 data bits. Then you can append a parity bit. This is optional. The parity bit can be calculated in software or you can let the hardware append the parity bit. There are many options.

Here are some examples:

1) Send 8 bits, no parity.
2) Send 8 bits, 7 bits of data and calculate the parity bit yourself.
3) Send 7 bits and ask the UART to append a parity bit (8 bits total are transmitted).
4) Send 8 bits and ask the UART to append a parity bit (9 bits total are transmitted).

In summary, the MCU does not decide if the parity bit is 0 or 1.
You calculate this yourself or you let the UART do it for you.

At the receiving end, you either let the UART indicate if the parity bit is correct or you check it yourself in software.
 

WBahn

Joined Mar 31, 2012
29,865
Hello,

Suppose we are working with a microcontroller that sends many bytes continuously to a UART device. I I'm curious about how the microcontroller decides whether it should set the parity bit to 1 or 0 when sending byte to the UART device. Could someone please explain the process or criteria that the microcontroller uses to determine the parity bit setting?

Thank you!"
Simple. The parity bit it set so that the overall parity of all of the bits, including the parity bit, match the parity requirement.

If the parity is set for even parity, then if the parity of the data bits is odd, the parity bit is set to 1, otherwise, since the parity of the data bits is already even, the parity bit is set to 0 to keep it even.

How this is done depends on the platform. When I designed a UART for a chip (there was no micro involved, everything in hardware), I simply used each outgoing data bit to toggle a T-flip flop when the data was HI. When it got time to send out the parity bit, I just transmitted the output of the TFF (or it's complement, depending on whether parity was even or odd).
 
Top