2

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.

dsolimano
  • 8,870
  • 3
  • 48
  • 63
sean
  • 717
  • 2
  • 9
  • 23

1 Answers1

7

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.

G.Y
  • 6,042
  • 2
  • 37
  • 54
  • 1
    Having once (a long time ago) worked on protocols for serial magnetic tape I can say that what you say is true, but there are a few other considerations as well, of a similar nature. – Hot Licks Feb 17 '14 at 03:49
  • @HotLicks I'm aware of those too.. but if I included those in my answer.. the amount of "flame-potential" would be much higher :) And, I would like to buy you a beer if we ever meet. – G.Y Feb 17 '14 at 03:53
  • 1
    seems 0x3c would be better for this purpose (or 0x3e for that matter). and one can even work out the exact best # assuming all bits have equal prob of being dropped (and it is probably not 0x7e).. why use 0x7e? – thang Feb 17 '14 at 04:12
  • @thang I believe the assumption is incorrect.. a 1 is much likely to be dropped than 0.. to transmit 1 - a pulse need to arrive from one side to the other but to transmit 0 - nothing need to arrive.. yet something can be spiked in some cases - but it is less to happen.. also the occurance of ~ as data is statistical less than <.. but please don't make me defend it :) – G.Y Feb 17 '14 at 04:26
  • Hi G.Y , your answer is great. Just wondering if there is there a reason why dont we used something which does not appear on the ascii table such as 0x81 1000 0001 ? – sean Feb 17 '14 at 05:47
  • @sean if 0x81 is used in 8bit frames which means we "parallel" 8bit ascii table (or the extended ascii table) - then it does appear in ascii table.. but if used in 7bit frames it means 2 frames are used to recognize the signal in your example.. so it is actually going to look like 1000000 1000000 - which is probably longer than needed and more error prone. – G.Y Feb 17 '14 at 10:26
  • i think that in all likelihood, anything that is a few zeros, a bunch of 1s, and a few zeros (or the ~ of it) would work. they probably picked 0x7e because it's not likely to be used often in the stream (and 7-bit). 0x7e is also used as an ESC code. not sure I buy the 1 more likely to be dropped than 0 because a lot of times, the lines are inverted on the wire (e.g. RS-232). – thang Feb 17 '14 at 14:37
  • @thang To me development is the application of 5774 years of evolved philosophy concepts in its most pure form expect perhaps the creation of this world itself.. so I cannot really be the dude to defend an arbiter or even slightly arbiter choice in coding :) – G.Y Feb 17 '14 at 15:32