6
\$\begingroup\$

I have sent a 2 and a 9 using UART. The baud rate is 9600, there is no parity, and it has 8 data bits.

As we know 9 is represented as 1001 in binary. However, this is what I get from my UART signal:

enter image description here

A 2 is represented as 0010 but this is what I get from my UART signal: enter image description here I know I have to pay attention to the start bit, but other than that, I have a hard time seing the logic in this signal.

NOTE:

The signal works, but I just need help analysing it.

\$\endgroup\$
2
  • 5
    \$\begingroup\$ Without even looking at the waveform, you may be confusing binary numbers and ASCII character codes, eg, the numeric value 2 vs the character '2' which has the ascii code 0x32. Also please don't use random tags, tags are for what a question is about now what was tangentially involved but plays no part in your post. \$\endgroup\$ – Chris Stratton May 25 '20 at 16:23
  • 4
    \$\begingroup\$ Your scope looks modern enough to have UART decoding, although perhaps it's also new enough that you have to pay for the privilege. \$\endgroup\$ – pipe May 26 '20 at 22:27
36
\$\begingroup\$

Let's annotate your first scope shot. When we do this take note that the lowest order bit of the binary value is transmitted first. Conventional notation in this field is to order the bits in a byte like this:

[Bit 7][Bit 6][Bit 5][Bit 4][Bit 3][Bit 2][Bit 1][Bit 0]

So when I annotate and then evaluate the bit positions are flipped from the positions shown on the annotated scope shots.

enter image description here

The bit pattern represented there is 0b00111001.

That is the same as 0x39.

0x39 is the ASCII code for a '9' character.

Let's do the same for your second scope shot.

enter image description here

Here the bit pattern is represented as 0b00110010.

That is same as 0x32.

0x32 is the ASCII code for the '2' character.

\$\endgroup\$
13
  • 3
    \$\begingroup\$ Start bits are always a zero level bit and are the same width. Your second pictures red lines are actually marking bit 1. Bit 0 is not skipped. \$\endgroup\$ – Michael Karas May 25 '20 at 16:53
  • 3
    \$\begingroup\$ Stop bits are always a one level bit and are the same width. The stop bit is not part of the UART 8-bits data. \$\endgroup\$ – Michael Karas May 25 '20 at 16:54
  • 3
    \$\begingroup\$ No. The start bit is clearly marked in my annotations and is not Bit 0. \$\endgroup\$ – Michael Karas May 25 '20 at 16:56
  • 6
    \$\begingroup\$ You are reading them backwards. LSB means least significant bit comes first. You need to invert them left to right. \$\endgroup\$ – evildemonic May 25 '20 at 17:11
  • 6
    \$\begingroup\$ I denoted the bit numbers in the pictures. In this discipline bit 0 is the least significant bit. \$\endgroup\$ – Michael Karas May 25 '20 at 17:48
10
\$\begingroup\$

You probably sent an ASCII 9, not a binary 9. ASCII 9 is 0x39. Bits are sent LSbit first.

0011 1001 reversed is 1001 1100

enter image description here

\$\endgroup\$
8
\$\begingroup\$

UARTs usually send the least-significant bit first hence you get this for 9 and lower down for 2: -

enter image description here

UART character frame: -

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Oh misery, a downvote - anyone feel man-enough to own up to this? \$\endgroup\$ – Andy aka May 26 '20 at 12:20
  • \$\begingroup\$ I didn’t downvote, but your answer is the only one that doesn’t mention ASCII. \$\endgroup\$ – Jacob Krall May 27 '20 at 22:04
7
\$\begingroup\$

First of all, those are not numbers 9 and 2, but ASCII character symbols '9' and '2', which equal to 0x39 and 0x32.

The bits are also sent LSB first. That's why you see a leading 0 start bit, and then 10011100 for '9' and 01001100 for '2'.

\$\endgroup\$
5
\$\begingroup\$

The 2 that you sent is actually the character two, not the decimal value of 2. The ASCII code for 2 is 0x32 or 0b00110010, which matches one of your images. Also, the bits are sent from LSB to MSB, so the levels you see on the 'scope would be 0,1,0,0,1,1,0,0 from left to right.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.