what does the 'parity' do in serial in serial coms?

BrendanP

Senior Member
Im doing some serial coms with the picaxe to a pc and a gsm module development board. What does parity actually do? Why do some devices require 'N' and others 'T' settings?

 
 

inglewoodpete

Senior Member
Nowadays, the true meaning of parity for asynch data transmission is almost forgotten.

Error checking is often omitted at the data layer (layer 2) of the 7 layer OSI model, due to the error checking available in upper layers (3-7).

In the early days of data transmission, there were very few of the upper layer protocols (Eg IP, TCP, UDP etc) we have today to indicate the quality of a data transmission.

The term 'parity' was to ensure that there an even (or odd) number of '1' bits in each character: a simple error checing method.

The parity bit was included in the transmission of each character (now byte) as a 1-bit checksum. This was intended as a quality check on each byte to help indicate data corruption.

Parity can be:
None: means don't include the parity bit. Each character will be 1 bit shorter than if parity is included.
Mark: always insert a '1'
Space: Always insert a '0'
Even: Parity bit indicates that the data contained an even number of bits set to 1
Odd: Parity bit indicates that the data contained an odd number of bits set to 1

Note that both ends must agree on whether a parity bit is to be used, although the receiver can sometimes be set to ignore the bit, where included.
 

BeanieBots

Moderator
Just to add to inglewoodpete's exellent description of parity, the "N" and "T" settings are to specify if the data is True or inverted. ie. a "1" is sent as a "0" or a "1".
This comes about because many serial lines are driven by a driver chip. The driver often inverts the signal and hence some method is required to determine if the sent (or received) signal has been inverted.
Again, as with parity, the important thing is that both sides agree.
 

Technical

Technical Support
Staff member
Do not confuse polarity with parity.

T (true) and N (inverted) are polarity (idle high or idle low) not parity.

All PICAXE serial comms is always "8,n,1"
- 8 bits, no parity, 1 stop bit.
 

BrendanP

Senior Member
Thanks guys for the help. So from what technical this mean then that parity isnt abale to be used with picaxe serial comms for error checking? What options are availible to me to then to ensure that the data sent and the data recievd is the same? Or are errors in serial comms so rare its not worth worrying about. Im a bit confused. Im sering out AT comms,phone numbers and sms's to the GSM module so its important the data isnt corrupted.

 
 

BeanieBots

Moderator
Even if parity was used, all you would know is that an error happened. You would still need to set up a method where the receiver could request the message to be sent again.
To ensure perfect comms, you will need to write a top level checking program. This would echo back what is received and take appropriate action if it does not match what was sent.

The reliability of serial comms depends a lot on length of cable, speed of transmission and the local electrical noise. Two PICAXEs on the same board with pins connected directly should be extremely reliable.
 

womai

Senior Member
One common way of detecting errors is to use checksums. That's some number that gets calculated from (and transmitted with) the actual data. The receiver performs the same calculation on the received data and verifies that its calculated checksum matches the received one. If there is a mismatch, an error has occurred.

One way to recover from errors is to let the receiver acknowledge each packet of data (i.e. send an answer back to the sender). If the receiver reports back an error, the sender then resends the packet.

A simple way to generate a checksum is to XOR all the data bytes of the packet together (byte1 xor byte2 xor byte3 ...). That at least assures that each bit of the data is significant (i.e. any single bit error will cause the checksum to change). This method detects all single bit errors and a large portion of higher-bit errors (2 or more bits corrupted). Of course there are more sophisticated schemes like CRC (cyclic redundancy check) etc, but an XOR checksum is easy and fast to implement on a Picaxe.

The parity is in fact such an "XOR-checksum", although it's only one bit long, so for example it does not catch any 2-bit errors.

Wolfgang


Edited by - womai on 16/03/2007 01:35:51
 
Top