Re: Serial communication, detecting parity bits



Mattias Brändström wrote:
Tauno Voipio wrote:

kobus wrote:


IIRC, the Stick Parity bit in the 8250 -family of serial interfaces
by-passes the parity generation, creating a ninth bit which can be controlled with the even/odd parity bit. Similarly, a received ninth bit can be detected as a parity error state change.



I have now been able to look a bit more closely at the serial port api in Linux. It seems that I can detect parity errors by setting PARMRK bit with tcsetattr(). Since the protocol that I have to use does not use any parity but uses the wakeup bit I can set my serial port to use either even or odd parity and then bytes that has a parity error will be prefixed with the bytes 0xff and 0x00. This will enable me to calculate what value the wakeup bit had for each byte.


The only thing I worried about now is what will happen if my the data stream contains the combination 0xff 0x00. How do I know that that combination is legitimate data and not a parity error?

Maybe someone has a nice solution to this?

:.:: mattias

The classic method for coding out-of-band data is similar to that used in PPP: christen one byte code (not either of the codes already out-of-band), e.g. 0x7d to mark out of band data and add the code there suitably modified.

The PPP method uses 0x7d to escape the control characters:
if there is a reserved code in the data payload, replace it
by the bytes 0x7d, data xor 0x20. This transforms the unhandleable
code to something that can be sent. The receiving end has
to detect the marker byte (0x7d) and decode the next byte
as the real payload byte. Of course, the marker byte has to be
encoded if it occurs in the payload.

Using this method, the bytes will be coded:

   payload byte    encoded sequence
   ------------    ----------------

    0x00             0x7d 0x20
    0x7d             0x7d 0x5d
    0xff             0x7d 0xdf

HTH

--

Tauno Voipio
tauno voipio (at) iki fi
.



Relevant Pages

  • Is it possible to implement UART by GPIO?
    ... Receiving would be even harder because you would have to tell the ... Are you sure it's not 8 + parity? ... have to be fast enough to check the parity error after every single ...
    (microsoft.public.windowsce.platbuilder)
  • Re: bit operations and parity
    ... // appendpayload) to what I am reading ... means "The total number of 1-bits, data and parity all taken ... something about bit-fiddling on your own. ...
    (comp.lang.java.programmer)
  • Re: bit operations and parity
    ... for an input byte 'inby' with the upper 7 bits as payload and ... the lowest bit as parity: ...
    (comp.lang.java.programmer)
  • Re: bit operations and parity
    ... 7E1 (7 bits with 1 parity bit, even parity) how do I break apart each ... byte in the byte array into the constituent 7 bits (as the ASCII code ... The operand (maskend?) to use depends on which bits you want to mask. ... for an input byte 'inby' with the upper 7 bits as payload and ...
    (comp.lang.java.programmer)
  • Re: wince serial driver
    ... I am using the parity bit as a signal bit ... it raises a parity error. ... But if I try to port the application to an ARM platform ... >> The Data Read out is from IST and WaitCommEvent is call from Application ...
    (microsoft.public.windowsce.platbuilder)