I am asking this stupid question for my general knowledge. Why in serial protocol often send least significant bit first? For example, in UART, data byte 10101100b (0xAC) is send as 00110101b (0x35). What protocol designer may have considered?
-
\$\begingroup\$ If your working in assembler there may just be a convienient instruction that helps make it easier ("Skip if [counter] zero" for example, then a count down is better). However all the protocols related to PC serial ports use Most Signifcant Bits first. If you control the the TX and the RX then it doesn't matter except when some one else needs to decode it. .. \$\endgroup\$– SpoonCommented Apr 10, 2014 at 11:44
2 Answers
if you are building up a number in binary, the 'right hand' bit is the least significant, and the processes is usually counting 'up' the index, or 'bit position' which goes left towards the most significant bit. This of course is entirely related to the "endian-ness" of the system architecture - which determines if it's the 7th or the zero-th bit as most significant.
A psuedo code for the receiver in a shift register of a UART might be:
- Oh look, i detected a start bit!
- oh look here are more bits coming in which match my baud rate settings! (timeout hasn't occurred, and not too fast to be considered noise, etc)
- for each bit, starting index 0, if bit is high, put a 1 into the shift register, else put a zero into the shift register
after the x number of data bits (could be 8-10 data bits in a serial frame) process is finished, and set flag for microcontroller to read my receive data register!
All of this is followed of course by 1 or 2 stop bits, and then the data line is kept at whatever idle level (usually high?) until the next transmission is detected.
Same style of thinking is used for bit-banging by software serial - as the pin level changes, increase the bit index and set/reset the bit on a "received byte" variable. It's essentially based on endian-ness of the system (little or big endian) and the fact that programmers like to use 0-indexing and starting at the lower end of a variable. Hardware UART transmit shift registers usually shift data out "backwards" than what you expect, as you mentioned in your question.
-
\$\begingroup\$ I downvoted this because it makes no sense. It is just as easy to make circuitry which receives the highest bit first, as it is to make circuitry which receives the lowest bit first. \$\endgroup\$ Commented Jun 26, 2021 at 11:25
-
\$\begingroup\$ @user253751 my answer doesn't say it's more difficult to do it one way or another. I explained the general process of receiving bits, and that the endianness of the system can dictate how they deal with bits (which may also go into how they are sent/received). \$\endgroup\$– KyranFCommented Jun 27, 2021 at 8:47
-
\$\begingroup\$ Endianness applies to bytes within a multi-byte value; the bits within a byte could be called endianness, but it's orthogonal to the endianness of multi-byte values. In fact, bit-within-byte-endianness is totally invisible to software! \$\endgroup\$ Commented Jun 28, 2021 at 11:24
As far as I'm aware, it was an arbitrary choice made at the time the async serial protocol was conceived. Other serial protocols, e.g. SPI, send the MSB first. The latter seems more natural to me, but ultimately it makes very little difference.