Parity in serial communication is a fundamental error-detection mechanism used to verify the integrity of data transmitted between devices. It is an optional parameter, used in serial communications to determine if the data character being transmitted is correctly received by the remote device, ensuring a basic level of data accuracy.
Understanding the Parity Bit
Unlike essential framing bits such as start and stop bits, the parity bit is an additional bit appended to a data character (like an ASCII byte) before transmission. Its sole purpose is to help the receiving device detect if a single bit error occurred during transmission.
When a device transmits data, it calculates the parity bit based on the number of '1's in the data character according to a pre-agreed parity setting. The receiving device then performs the same calculation on the received data and its parity bit. If the calculated parity doesn't match the received parity bit, it indicates that an error occurred during transmission.
How Parity Works
The concept behind parity is simple:
- Sender Calculation: The sending device counts the number of '1's in the data byte.
- Parity Bit Generation: Based on the chosen parity type (e.g., Even or Odd), a parity bit (0 or 1) is added to make the total count of '1's (including the parity bit) conform to the chosen parity.
- Transmission: The data byte, along with the newly added parity bit, is transmitted.
- Receiver Verification: The receiving device performs the same count of '1's on the received data byte and the parity bit. If the count matches the agreed-upon parity setting, the data is considered valid. If not, an error is detected.
Types of Parity
Different parity settings offer various ways to check data integrity:
Parity Type | Description | Example (Data: 01000001 - 'A') |
---|---|---|
None | No parity bit is used. No error checking is performed at this level. | Data: 01000001 |
Even | The parity bit is set to 0 or 1 to make the total count of '1's (including the parity bit) an even number. | 'A' (01000001) has two '1's. To make it even, a '0' parity bit is added. Transmitted: 010000010 |
Odd | The parity bit is set to 0 or 1 to make the total count of '1's (including the parity bit) an odd number. | 'A' (01000001) has two '1's. To make it odd, a '1' parity bit is added. Transmitted: 010000011 |
Mark | The parity bit is always set to '1'. This doesn't provide error checking but ensures a logic high for timing purposes. | Transmitted: 010000011 |
Space | The parity bit is always set to '0'. This doesn't provide error checking but ensures a logic low for timing purposes. | Transmitted: 010000010 |
Practical Considerations and Limitations
- Configuration: For successful communication, both the transmitting and receiving devices must be configured to use the same parity setting, along with other serial port parameters like baud rate, data bits, and stop bits.
- Error Detection, Not Correction: Parity can detect if an error has occurred, but it cannot identify which specific bit was flipped or correct the error. Upon detection, the receiving device typically discards the faulty data or requests retransmission if the protocol supports it.
- Single-Bit Error Detection: Parity is effective at detecting single-bit errors. However, if two bits within the same data character are flipped (e.g., a '0' becomes '1' and a '1' becomes '0'), the total count of '1's might remain the same, causing the error to go undetected.
- Optional Parameter: As highlighted, the parity bit is an optional parameter. Many modern serial communication protocols rely on more robust error-checking mechanisms (like Cyclic Redundancy Checks - CRCs) at higher layers of the communication stack, making parity less critical or often omitted. However, for simpler devices and legacy systems, parity remains a common setting.
Parity serves as a basic, hardware-level check to ensure the integrity of individual data characters during serial transmission, making it a foundational concept in data communication.