Search code examples
serial-portserial-communicationxbee

Why is 0x7E commonly used as Start Delimiter in Communication Protocol?


i am looking to implement a serial communication between 2 devices using just a simple communication.

It seem that protocol such as those used in HDLC and xBee uses 0x7E as the start delimiter.

Is there any particular reason or i can use any character as an alternative.


Solution

  • The reason is related to framing of data.

    • They needed a flag that will mark a beginning and an end of transmission.
    • They wanted to be able to replicate that flag few times if needed - in example if you send
      01111110 01111110 01111110 - it is very easy to identify this set compared to other sets even if some bits didn't made it to the other side, so it is uniquely much less error prone.
      (0x7E=01111110)

    Extended Example:

    machine 1 sent: 01111110 01111110 01111110
    some options for error in receive:
    machine 2 recv: 011110011111001111110 - notice that you can identify 3 frames very easy.
    machine 2 recv: 11111001111110011111 - again you can identify 3 frames quite easy.
    machine 2 recv: 01111110111111001111110 - once more 3 frames can be identified quite easy.

    Now let's see what happens if we choose different sequences as flags.

    Example 1:

    machine 1 sent: 01011010 01011010 01011010 (here flag chosen is 01011010)
    some options for error in receive:
    machine 2 recv: 010010100101101001011010 - you cannot identify if those are even frames..

    Example2:

    machine 1 sent: 00011000 00011000 00011000 (here flag chosen is 00011000)
    some options for error in receive:
    machine 2 recv: 00110000001100000011000 - this one is ok... we can easy see 3 frames.. but..
    machine 2 recv: 0010000001100000011000 - this is harder.. could be 3 frames but can't be sure..

    You can read more in Wikipedia information about HDLC (check the frames subject)

    One more thing.. SO Folks I know this has a flame potential :)
    Please keep in mind I didn't choose this arbiter sequence.. I only explain the reason for this particular sequence as choice.