14
\$\begingroup\$

I tried to see an ASCII "A" character with an oscilloscope but the real binary value and oscilloscope values are different why is that? ASCII "A" Binary value - 01000001

The oscilloscope displays this graph:

Ascii A

Ascii A

I use an Arduino Uno to send the ASCII value using the code:

void setup() {  
  Serial.begin(9600);  
}  

void loop() {  
  Serial.println("A");  
  delay(1000);  
}
\$\endgroup\$
35
\$\begingroup\$

Here's how you read the oscilloscope waveform. I took the time to edit your waveform picture and annotate it to show which bit is which. The microcontroller sends 10 bits per character; START, which is always 0, 8 data bits and STOP which is always 1. The line also rests at 1, so the first START falling edge alerts the receiver that a bytes is coming. The bits are sent LSB first, so if you want to "take a look" at them aritmetically, you need to mirror them horizontally for them to make any sense. The width of each bit is determinated by the baudrate, and the transmitter and receiver must both know what the baudrate is.

From the below picture you can see that it sends three characters: ASCII character 'A', a carriage return and a line feed.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ If it is serial communication, wave give like this. right? What are CR and LF? What are other data can get like CR or LF? \$\endgroup\$ – user38701 Sep 24 '15 at 1:53
  • 1
    \$\begingroup\$ CR is Carriage Return, LF is Line Feed. Together they form a Newline, e.g. the cursor goes to the beginning of the next line. They are part of "ASCII" standard ("American Standard Code for Information Interchange"), google "ASCII chart" or something. \$\endgroup\$ – PkP Sep 24 '15 at 3:48
  • \$\begingroup\$ @user38701: CRLF is what happens when you press the enter key. Technically, CR is supposed to be the return key and LF is supposed to be the enter key but serial console interprets the enter key to be CRLF (or sometimes just LF). In most programming languages, CR is "\r" and LF is "\n" but some compilers/languages output CRLF for "\n" \$\endgroup\$ – slebetman Sep 24 '15 at 10:20
  • 1
    \$\begingroup\$ The carriage return is simple. He used a println command, which means print the string, as well as a "\r\n". So three characters \$\endgroup\$ – ps95 Sep 24 '15 at 15:30
  • 1
    \$\begingroup\$ it's worth noting line terminations are system-specific.CRLF is primarily the Windows and Arduino line termination. If you repeated the same test using a terminal on linux as the source of the "A", you'd only see the LF. \$\endgroup\$ – Nicolas Holthaus Sep 24 '15 at 17:24
13
\$\begingroup\$

If you look at the Arduino println() documentation you'll see that it appends a carriage return and linefeed at the end. So in decimal you will end up with 65 (A), 13 (CR) and 10 (LF) which in binary translates to:

01000001 00001101 00001010

Async serial data is sent LSB first so that becomes:

10000010 10110000 01010000

Your signal is idle high so the start bit will be 0 and the stop bit will be 1 so adding that to each byte and you end up with:

0100000101 0101100001 0010100001

It's a bit hard to work out the exact timing from your diagram but that seems to at least roughly match up and should give you an idea where some of the extra bits come from and why they are re-ordered. The Wikipedia link provided by Kvegaoro gives a lot of good background information on async serial data.

\$\endgroup\$
1
\$\begingroup\$

If that stream you show there is Asynchronous serial, the oscilloscope will show the corresponding start bit, stop bit(s) and parity bits. Also take into account if your signal is inverted or not and weather it is Most significant bit first or leas significant bit first. If you add more details about the serial stream you have represented in the picture, , we can give you a better more detailed answer otherwise this is just an educated guess

\$\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.