Saleae Support
HomeDownloadUser ForumContact Us
  • Saleae Support
  • Orders & Shipping
    • Place an Online Order
    • Place a Purchase Order (PO)
    • Get a Quote
    • Check your Order Status
    • Distributors
    • Pricing and Availability
    • Discounts
    • Tax & VAT Exemption
    • Saleae Business Information
    • Shipping Policy
    • Receiving Invoices
    • Sales FAQ
      • What Is Included with the Product?
      • What Accessories Should I Purchase with My Device?
      • Is the Saleae Software Sold Separately?
      • Does Saleae Have a Trade-In or Upgrade Plan?
      • How Can I Find the Current Status of My Order?
      • Part Numbers, ECCN, HS Codes, and Country of Origin
      • Discontinued Products
      • International Customs and Duty Information
      • Does Saleae Offer Demo Units or Units on Loan?
      • When Is My Card Charged?
      • Unable to Ship to PO Box Error
      • Referred a Friend? Email Us!
      • Does Saleae Provide Drop-Shipping Service?
  • Getting Started
    • Setup
    • Configure
    • Record
    • Navigate
    • Measure
    • Trigger
    • Protocols
  • User Guide
    • Product Summary
    • Safety & Warranty
    • Supported Voltages
    • Device Calibration
    • Using Logic
      • Navigating the Software
      • Connecting the Logic Analyzer
      • Logic Accessories
      • Device Settings
      • Capture Modes
      • Navigating Your Data
      • Time Bar Settings
      • Measurements, Timing Markers & Notes
      • Capture & Preset File Management
      • Exporting Data
      • Delete Part of your Capture
      • Analyzers
      • Data Table & Terminal View
      • Color Themes
      • Demo Mode
      • Software Glitch Filter
      • Keyboard Shortcuts
      • Automatic Updates
      • Message Us Directly
  • Software
    • Supported Operating Systems
    • Download
    • Installation
    • Firmware Updates
    • Driver Install
    • Legacy Software
      • Logic 1.x Download (Deprecated)
      • Logic 1.x Installation (Deprecated)
      • Logic 1.x Changelog (Deprecated)
      • Logic 1.x User Guide (Deprecated)
  • Protocol Analyzers
    • Supported Protocols
    • Analyzer User Guides
      • Async Serial Analyzer - User Guide
        • Decode UART
        • Decode RS-232, RS-485, & RS-422
      • SPI Analyzer - User Guide
      • I2C Analyzer - User Guide
      • CAN Analyzer - User Guide
      • Simple Parallel Analyzer - User Guide
      • I2S / PCM Analyzer - User Guide
      • DMX-512 Analyzer - User Guide
      • SMBus Analyzer - User Guide
      • Decode Differential and High Voltage Data
  • Software Extensions
    • Extension Installation
    • Create and Use Extensions
    • High-Level Analyzer (HLA) Extensions
      • Shared High Level Analyzers (HLAs)
    • Measurement Extensions
      • Analog Measurement Extensions
      • Digital Measurement Extensions
    • Extension File Format
    • About Third-Party Extensions
    • Disabling Marketplace Extensions
    • Publish an Extension
    • HLA - Analyzer Frame Format
      • Async Serial - Frame Format
      • I2C - Frame Format
      • SPI - Frame Format
      • CAN - Frame Format
      • Manchester - Frame Format
      • 1-Wire - Frame Format
      • Async RGB LED - Frame Format
      • Simple Parallel - Frame Format
      • LIN - Frame Format
      • I2S - Frame Format
    • API Documentation
  • Automation & Analyzer SDK
    • Automation API - Logic 2
    • Automation API - Legacy Logic 1.x
    • Protocol Analyzer SDK
      • FrameV2 / HLA Support - Analyzer SDK
      • Rename a Custom Analyzer
    • More Information on our SDKs
      • Can I Access Raw Data in Real Time?
      • Migrate Code to the New Analyzer SDK
      • Sharing Custom Low-Level Analyzer (LLA) Code
      • VB.NET Support for Automation
  • Datasheets & Specifications
    • Datasheets
    • Logic Hardware Revisions
    • Logic Dimensions
    • Compliance Documents
  • Troubleshooting
    • Installation Errors
    • The Software Fails to Launch
    • The Software Crashes
    • Logic is Not Detected
    • Getting your Machine ID
    • Getting your Software Crash Logs
    • Getting the Console Output
    • Location of Your Config File
    • Error Message: ReadTimeout
    • The Captured Data Looks Incorrect
    • The Captured Data is Corrupted
    • A Protocol Analyzer Produces Unexpected Results
    • The 'Waiting for Trigger' Window Never Closes
    • Device USB VID and PID Information
    • Error Message: Out of Memory Exception Was Thrown
    • PC Performance Issues with Logic
    • Data Export Is Not Working
    • Error Message: A device was found, but the software was unable to access it
    • Trouble Downloading the Latest Software
    • Logic Does Not Connect over USB 3.0
    • Why Am I Seeing Spikes in the Digital Capture?
    • Logic Interferes with My Circuit Operation
    • The Add Analyzer Menu Is Not Displaying
    • Other Drivers Interfere with Logic's Operation
    • The Maximum Sample Rate is Not Selectable
    • The Digital and Analog Recording on the Same Channel Appear Different
    • Advanced USB Debugging for USB 3.0 Users with Linux Kernels 3.3 and Older
    • Saving or Loading Anything Crashes the Software
    • Error Message: The application was unable to start correctly (0xc0000005)
    • Memory Usage with Triggered Captures
    • The Cabinet File disk1.cab has an Invalid Digital Signature (Logic 1.x)
    • Software Crashes with Virtual Desktops
    • Pre-Trigger Buffer is Incomplete
    • Linux Shared Memory Crash
    • Missing Files: api-ms-win-crt-runtime-l1-1-0.dll or msvcp140.dll
    • Known Issues on OS X
    • A Measurement Appears Incorrect
    • All Known Issues
    • USB 3.0 Cable Customer Notice (2017)
    • Warning Message: Logic Pro is running as a USB 2.0 device
    • Software Issues with Encryption Products
    • Linux Permission Requirements for Logic Software
    • My Rise Time and Fall Time Measurements Seem Incorrect
    • The Analog Waveform Loads Very Slowly after Capture Is Complete
    • Input Channels are Missing
    • Exported MATLAB File Does Not Open
    • Saleae Logic LED Blinks Red
    • Crashes Caused by macOS Mojave (10.14)
    • Troubleshooting Signal Crosstalk
    • Error Message: DeviceSetupFailure
    • Error Message: Unable to detect WebGL and Other GPU Issues
    • Warning Message: Unsupported Version
    • Error Function: Device2::SetupDevice
    • Warning Message: Possible USB Host Controller Problem Detected
    • Error Message: StartCommandError
    • Logic 2 Error Messages
    • PC Detection Test
    • CentOS Compatibility Issues
    • Error Message: Failed to Load Extension
    • CSV Export is Slow
    • Set an Analyzer Starting Point in your Capture
    • Logic 2 is Consuming Disk Space
    • Connection Conflicts with USB Debuggers
    • PC Restart Causes Logic to Disconnect
    • HLA Fails to Display Special Characters
    • Data Table Shows Incorrect Values
    • Error Message: Failed to Load Custom Analyzer
    • Error Message: Capture Stopped
    • Error Loading Marketplace Extensions
    • Error: Capture stopped because backlog data exceeded 90%
    • This Analyzer's Native Export is Not Supported in Logic 2
    • Mouse Scrolling Issues
    • Error: A device was found, but it was removed before initialization completed
    • Error: An unknown error occurred during device connection
    • Visual Studio Error: Failed to Launch Debug Adapter
    • VS Code Fails to Launch Python Automation API Script
    • Analog Waveforms Do Not Appear on Linux
    • Reinstall USB Host Controller Drivers
  • FAQ
    • Technical FAQ
      • System Requirements for Saleae Products
      • What Is the Normal Behavior of the LED?
      • What Is the Difference between Logic/Logic16 (Gen1) and Logic 8/Pro 8/Pro 16 (Gen2)?
      • Recommended USB 3.0 Host Controller Cards
      • Device Settings Configuration Tips
      • What Is the Worst Case Channel to Channel Skew?
      • What is Asynchronous Sampling?
      • Which Saleae Products Can Decode 4-Bit Parallel LCD Communications?
      • How Can I Compare Two Clock Signals for Synchronization and Drift?
      • Converting I2S/PCM Captures into Audio
      • My Capture Shows an Uneven Duty Cycle
      • Can I Create or Edit .logicdata Files?
      • Can Saleae Logic Run on ARM / Apple Processors?
      • What Annotations Are Supported?
      • Time & Memory Saving Tools
      • How Can I Record Power Consumption?
      • Moving Logic to Its Own Host Controller
      • How Long Does It Take to Save a File?
      • XMonad on Linux Causes Issues
      • What Is the Maximum Bandwidth of Logic?
      • How Long Can I Record Data?
      • Can I Export Protocol Results Between Timing Markers?
      • Can I Generate an Analog Graph from Digital Data?
      • Time Measurement Error
      • Can These Products Replace an Oscilloscope?
      • Can I Use Multiple Logics on a Single PC?
      • Native Windowing Features Are Not Working Such as Snap or Gestures
      • Opening .logicdata Capture Files
      • How to Choose the Right Logic Analyzer for You
      • Saleae Open Source Support
      • How to Trigger the End of a Capture Instead of the Start
      • Using the Hardware with USB Extension Cables, Through Virtual Machines, or Ethernet Extenders
      • Are the Ground Pins Required for Each Input Used?
      • Can Saleae Products Output Data?
      • Resolution of the Analog Inputs
      • What Sampling Rate Should I Use?
      • Can I Share Data Captures with Others?
      • Binary Export Format (Digital) - Logic 1.x
      • MATLAB Data Export Format - Legacy Logic 1.x
      • Recording Multiple Protocols at the Same Time
      • Changing the Display Radix (Base)
      • Which Logic Analyzer Should I Get?
      • How to View and Debug Firmware Variables, State, and Function Calls
      • Using Saleae Logic Devices with Third-Party Pattern Generators
      • Can Logic Operate with a Full-Speed USB Isolator?
      • Which Saleae Devices Support Analog Recording?
      • How to Manage Protocol Analyzers when Using the Socket API
      • How to Export Serial Protocol Results to a Raw Binary File
      • How to Trigger On a Pulse with No Maximum Time Limit - Logic 1.x
      • Finding Your USB 3.0 Host Controller Information
      • Logic Reports Different USB Current Requirements
      • Is It Possible to Adjust the Logic Thresholds for the Digital Inputs?
      • Why Does Channel 0 Use a Black Wire?
      • Software Shows Multiple Logic Analyzers Attached
      • Are the Input Channels Isolated from Each Other?
      • Are There Feature Differences in the Software when Different Logic Analyzers Are Used?
      • Packet Level Decoding Support in the Analyzer SDK
      • What Higher-Level Protocol Analysis Features Are Available?
      • Support for USB 3.0 and USB 3.1
      • How Can I Compare Signals from Different Captures?
      • Do the Saleae Logic Analyzers Support Trigger Out?
      • Why is the Length of my Capture Incorrect?
      • The Options Button is Missing
      • Can I Change the Voltage Range of the Analog Inputs?
      • How Does the ASCII Radix Display Characters?
      • Do I Have a USB 3.0 Port?
      • What Is the Best Way to Compare Similar Sequences of Protocol Data?
      • Which Version of the Software Should I Use?
      • Import Custom Low Level Analyzer
      • OSX Analyzer SDK Xcode Setup
      • Can Custom Analyzers Process Analog Channels?
      • Automating Long Overnight Captures
      • What Options Are There to Export Multiple Protocol Analyzer Results into the Same File?
      • Do the Saleae Devices Support AC Coupling?
      • Suggestions for Capturing Multiple Instances of a Triggered Event Automatically
      • How Many Protocol Analyzers Can Be Used at Once?
      • Is It Possible to Run the Saleae Software on a PC without SSE2 Instructions?
      • Is It Possible to Import Data into the Logic Software?
      • How Do I Convert Exported CSV Analog Data in Voltages?
      • Is There Cross-Platform Support for the SaleaeSocketApi C# Project
      • Why Does Logic Get Warm?
      • Binary Export Format (Analog) - Logic 1.x
      • Electrical Isolation Suggestions
      • FCC and CE Testing Recommendations
      • 'Save Capture' and 'Export Data' is Disabled in the Software
      • File Format Description for Exporting Protocol Analyzer Results
      • Is There a Newer Version of the Software Available?
      • Is There a Way to Change the Window Resolution?
      • How Can I Extract Recorded Data Using Socket API?
      • Does the Software Support Windows 10 Tablets or Windows RT Tablets?
      • Standalone Software Information
      • Does the Saleae Software Support the Original Logic and Logic 16?
      • Timing Markers Disappear When I Start a New Capture
      • What Sample Rate Settings Are Available? Can I Sample at a Slower Rate?
      • How Do I Differentiate Data in the Export File when Duplicate Analyzers Are Used?
      • Running Multiple Versions of the Software
      • Test Clip Differences - Gen 1 & Gen 2
      • USB-C Cable Recommendations
      • Is My Capture Data Private?
      • Ethernet Connectivity Suggestions
      • Binary Export Format - Logic 2
      • Viewing I2C Addresses as 8-bit
      • Can I use Python Packages in my Custom Extension?
      • Are the Inputs Synchronously Sampled or Sweep Sampled?
      • Is Logic Affected by the Log4j Exploit?
      • Connecting Remotely with SSH
      • Is Silent Installation Supported?
      • Is the .sal File Format Documented?
      • Export Data via Socket API
      • Running Logic in a CI Environment on Windows with the SYSTEM Account
    • General FAQ
      • How Do I Get More Help on an Issue That's Outside the Scope of Saleae Support?
      • How to Identify Each Saleae Device
      • License for the Saleae Logic Software, SDKs, and APIs
      • How Do You Pronounce Saleae?
      • How to Create Project Content for Saleae
  • Returns & Warranty
    • Submit a Warranty Claim
  • Community
    • Ideas & Feedback
    • User Forum
    • Community Projects
    • Community Created Accessories
    • Community Shared Analyzers
  • Tutorials
    • Oscilloscope Tutorial
    • Logic Analyzer Tutorial
    • Learning Portal
      • Digital Protocols
        • Learn Asynchronous Serial
        • Learn I2C - Inter-Integrated Circuit
        • Learn SPI - Serial Peripheral Interface
        • Learn CAN – Controller Area Network
        • Digital MultipleX (DMX512)
        • Manchester
        • 1-Wire
        • Learn I2S / PCM
        • Management Data Input/Output (MDIO)
        • BiSS C
        • HDMI Consumer Electronics Control (CEC)
        • PS/2 Keyboard/Mouse
        • Universal Serial Bus (USB) 2.0
        • Single-Wire Interface (SWI)
        • Simple Parallel
        • Local Interconnect Network (LIN)
        • Joint Test Action Group (JTAG)
      • Common Acronyms and Definitions
      • What is a Glitch?
      • What is RAM? Why Does Logic Use it?
      • What is a Display Radix?
      • What is Data Bandwidth? Can I Reduce this in Logic?
    • Example Projects
      • STM32 Nucleo Board - Digital Signals
      • STM32 Nucleo Board - Analog Signals
      • STM32 Nucleo Board - Analyzing UART
      • STM32 Nucleo Board - Analyzing SPI
      • STM32 Nucleo Board - Analyzing I2C
Powered by GitBook
On this page
  • Learn Asynchronous Serial
  • Topology – Where Do the Wires Go?
  • Voltages
  • How Do You Transmit Information with Only One Wire?
  • The Bits on the Bus Go One at a Time
  • Sending Bits to a Friend in Another Room, Using a Switch
  • Ways your friend could get confused
  • More Speed, More Problems
  • The Solution, Part 1: Let's Agree to Periodically Resynchronize Our Clocks
  • Resetting the Clocks Every Time the Bit Changes from a 0 to a 1, or a 1 to a 0
  • But What If the Sender Is Sending a LOT of 0s or a LOT of 1s?
  • The Solution, Part 2: Idle Periods, Dedicated Start Bits, and Dedicated Stop Bits
  • Why Do We Need a Minimum, Guaranteed Amount of Idle Time—aka Stop Bits?
  • What's the Deal with 1.5 Stop Bits, or 2 Stop Bits, etc.?
  • What Happens after the Stop Bits?
  • What's a Framing Error?
  • A Framing Error Could Be Useful
  • What Order Do Data Bits Get Sent In—Most Significant Bit First, or Least Bit Significant First?
  • What's This About a Parity Bit?
  • Out-of-the-Box Limitations with Serial, and Some Ways to Improve It
  • What Exactly Does Asynchronous Serial Mean?
  • How Do I Use RS-232 Serial with a Microcontroller?
  • Is Async Serial on the Way Out?
  • Async Serial in a USB World
  • An Example of Receiving Serial Data on a Microcontroller
  • What Are the Settings for the Saleae Serial Analyzer?
  • Further Reading
Edit on GitHub
Export as PDF
  1. Tutorials
  2. Learning Portal
  3. Digital Protocols

Learn Asynchronous Serial

PreviousDigital ProtocolsNextLearn I2C - Inter-Integrated Circuit

Last updated 6 years ago

Learn Asynchronous Serial

Asynchronous serial (often called simply "serial") generally refers to single-wire, half-duplex communication where data bits are located at fixed time intervals after a start bit. Instead of using a dedicated clock line, asynchronous serial requires the receiver to sample the incoming signal at specific time intervals after a start bit's leading edge.

Topology – Where Do the Wires Go?

Async Serial data is sent with just one wire (not including ground). In most cases, there is one device that is the sender and one or more devices that listen.

If communication needs to be two-way, then generally you need to add another wire for the other direction. These wires are often referred to as TX (outgoing transmission) and RX (receiving line) to convey their direction with respect to a particular device.

Voltages

Serial uses two voltage levels to convey information—1 and 0. The exact voltages that represent 1 and 0 can be different, depending on the setup, but both sides of the communication need to use the same voltages. In "logic level" serial, the voltages are 0V for a digital 0 and the logic-high voltage for digital 1. (The logic high voltage would be something like 5V, 3.3V, etc., depending on the application.) When using the RS-232 electrical standard (used by older computers and equipment but still being used today, although considerably less so), Logic 0 is 15V, and Logic 1 is -15V. A bit backward-seeming, yes. A lot of equipment cheats a little and doesn't use +/-15V, opting instead for voltages that are easier to generate such as +/-7V. This is still RS-232 compliant and will work with RS-232 equipment.

Serial Type

Logic 0

Logic 1

5V

0V

5V

3.3V

0V

3.3V

RS-232

15V

-15V

How Do You Transmit Information with Only One Wire?

Since you only have one wire to work with, the only way to send information is by using some sort of timing scheme that both sides agree on. We'll start by agreeing on the amount of time each bit gets on the wire (we'll start calling it a bus now) before the next bit replaces it. Bus just means wire, or group of wires.

The Bits on the Bus Go One at a Time

When you talk about bit rates, you're really describing how long each bit has on the bus before the next bit gets put on the bus. For example, if you send 10 bits every second, each bit will get .1 seconds on the bus, and then the next bit will be placed on the bus.

Sending Bits to a Friend in Another Room, Using a Switch

Imagine you are putting bits on the bus, once every second. You use a stop watch. Every second, you decide the next bit to send and then move a switch to either on or off (1 or 0). It turns on (or off) a light in another room. Remember, the light may or may not change every bit. Maybe you need to send a lot of 1s in a row. For example:

In the middle of each second (.5 seconds after the new bit is on the bus and .5 seconds before the next one), your friend writes down the value—1 if the light is on, 0 if the light is off.

Ways your friend could get confused

However, there are some issues with this approach. For example, if you don't yell into the other room, how does your friend know exactly when you started sending bits?

What if their watch (or yours) isn't very accurate, and over a long time, they start writing down bits at the wrong times? They think they are writing down the bit exactly in the middle of the time it's on the bus, but that starts to drift. It can drift so far that ever so often they end up skipping a bit or adding an extra bit. You can imagine the mayhem that will produce if these bits are supposed to be grouped into bytes, which they usually are.

More Speed, More Problems

The faster that bits get put on the bus, the more difficult the issue becomes. Even small drifting in the sender’s and receiver’s clocks will mean losing track of what bit you are on. If each bit is only on the bus for 1 microsecond, you would have to have very accurate, expensive clocks on both ends to be sure you didn't drift more than 1 microsecond over a long period, maybe even hours or days.

The Solution, Part 1: Let's Agree to Periodically Resynchronize Our Clocks

If we could come up with a way to resynchronize our clocks ever so often, we could get away with cheap clocks that drift a lot. In fact, the more often we synchronize our clocks, the more errors we can tolerate.

Resetting the Clocks Every Time the Bit Changes from a 0 to a 1, or a 1 to a 0

Well, you might point out, one great way to synchronize our clocks would be to reset them every single time the bit on the bus changes from a 0 to a 1, or a 1 to a 0. That is a great idea! Congrats if you already thought of it.

But What If the Sender Is Sending a LOT of 0s or a LOT of 1s?

If the sender sends a lot of 0s or a lot of 1s, then we wind up with the same problem. We don't have a chance to resynchronize our cheap clocks.

You might think that won't happen in real life or not very often, in any case. But remember, we need a solution that works in general for every situation.

And how do we synchronize the very first time so we know for sure we have the very first bit?

The Solution, Part 2: Idle Periods, Dedicated Start Bits, and Dedicated Stop Bits

Idle Periods

Before data starts getting sent, we agree that we'll have something called Idle, where nothing is going on. Idle is when Logic 1 is on the bus for an extended period of time. Both sides—the transmitter and the receiver—agree that we'll both start up in this situation.

The Start Bit

Both sides agree that the very first thing that will happen after Idle is that a start bit is put on the bus. The start bit has the value of logic 0—otherwise, it would be the same as Idle after all, and we wouldn't have known it even happened.

When the Start Bit Starts—When the Logic Level Changes from 1 to 0—We Restart Our Clock

Remember, the start bit isn't data that we're trying to send. It's ALWAYS 0. No useful data are getting sent here. It's here to reset our clock and let us know that more bits are coming up.

The First Real Data Bit—The Bit That Comes after the Start Bit: What If It's Also a 0?

How do we know when enough time has passed that we're now in the middle of our first actual data bit? Simple: We time it. This is how the serial port on the IBM PC did it, and it's how a PIC or MSP430 or Arduino do it.

8 Data Bits – Why Not More or Less?

By convention, serial usually has 8 data bits after the start bit. It's enough for exactly one byte. However, any variation is possible, especially if you are making up your own serial data protocol. You can have as many or as few data bits as you like. Just remember the problem of timing drift (what if our nifty 128-bit serial packet was all zeros? We might need to have better, more expensive clocks or, equivalently, run at slower bit rates).

The Stop Bit – What Is It Even For? It Looks Indistinguishable from the Idle Period That Follows It

The stop bit (or bits) come after the very last data bit is finished. They are logic 1—the same as idle. In fact, there may be quite a bit of idle time after the stop bit.

Here's the secret. It's not really a bit. It's just a minimum, guaranteed amount of idle time.

Why Do We Need a Minimum, Guaranteed Amount of Idle Time—aka Stop Bits?

Well, we need to resynchronize. We need to make absolutely sure that the receiver can reliably detect the next start bit—even if its clock isn't very accurate. The less accurate our clock, the more idle time the better. In practice, a couple if bit times should be enough.

What's the Deal with 1.5 Stop Bits, or 2 Stop Bits, etc.?

As you've probably guessed by now, the more stop bits we put in, the more idle time we are guaranteeing there will be—and the less we need to rely on the receiver's (or transmitter's) clock to be really good.

What Happens after the Stop Bits?

What happens after the previous serial frame is completely finished, stop bits and all? One of two things: either some more idle time or the next start bit for the next set of data bits. That's why the stop bits are really a minimum, guaranteed amount of idle time.

What's a Framing Error?

Let's say you're listening to serial bit sequence—start bit, data bits, stop bit(s)—which is known as a frame. And let’s say you're listening to those stop bits that, as you might imagine, had better be logic 1s, the idle logic level.

Instead of logic 1s, however, you discover that they are 0s, or in any event, they aren't solid 1s. This is known as a framing error. It means that something has gone wrong and we're not synchronized properly. That could happen if we were assuming the data was a different bit rate than it really was, or if we started listening to serial data right in the middle of a transmission.

A Framing Error Could Be Useful

A microcontroller could use a framing error to try to synchronize itself with a serial transmission that it started listening to right in the middle. Ultimately, the only really 100% reliable method is to wait for a long idle period—at least one full serial frame's worth. That might not happen, however, unless the transmitter makes sure it does.

If the sender was sending a checksum, CRC, or some other known sequence, it would be possible to synchronize with a transmission that was already under way. Such algorithms are out of the scope of this article, but you probably already have some ideas on how it could be done.

What Order Do Data Bits Get Sent In—Most Significant Bit First, or Least Bit Significant First?

Most significant and least significant refer to the location of a bit in a byte. In the byte 128 (0x80, 0b 1000 0000), the most significant bit is a 1, and all the other bits are 0s. In the byte 1 (0x01, 0b 0000 0001), the least significant bit is a 1, and all the other bits are 0s.

The convention for async serial data is that the least significant bit goes first, and the rest of the bits follow in order. However, it can easily be the other way around, so be sure to check. Normal RS-232 style serial is always least significant first.

What's This About a Parity Bit?

The parity bit was an extra (9th, typically) bit that was added to a serial frame to act as a crude error detection mechanism.

If a system was using odd parity (that means that if you took all the data bits and the parity bit and added up all the 1s), it would give you an odd number. For example, if the byte was 0x01, then the number of 1s is already odd, so the transmitter would make the parity bit a 0. However, if the number of 1s was even (e.g., there were 4 1s), the parity bit would be set to a 1 so the total would become odd.

The opposite would be true for a system using even parity.

The idea was that if one of the bits was received incorrectly, there would be a parity error—the number of 1s wouldn't be the agreed upon even or odd. And the receiver would know then to reject that byte.

Note that this is a fairly primitive error detection mechanism by today's standards. A far better method of detecting errors is a CRC number or similar method. In addition, a method is needed to request that the failed series of bytes be retransmitted.

Out-of-the-Box Limitations with Serial, and Some Ways to Improve It

In addition to not having a good method to detect errors, there is also no way to address certain bytes to a particular receiver (if there is more than one). There is also no good method of reliably "dropping in" on an ongoing transmission.

These limitations can all be overcome by the addition of higher layers of abstraction. In fact, it is quite possible to run TCP/IP over a two-way serial connection.

A simpler improvement is MP Mode (also called 9-bit serial and multiprocessor mode). That adds an extra bit to specify if a given byte is an address or data. That allows many listeners on a single line to be given data (perhaps commands) individually.

You may want to invent your own, higher-level protocol. For example, you could create a packet structure where the first byte is a particular header code such as 0x21 (to pick a random number), the next 2 bytes was an address, the next 4 bytes were some data, and the last 2 bytes was a 16-bit CRC (or something like that). You could build up quite an impressive robust communication system using regular old serial as the transmission medium.

What Exactly Does Asynchronous Serial Mean?

Serial means one bit at a time, typically on one wire. The other option is parallel, which has many bits at the same time on different wires.

Asynchronous means that there's no one telling you exactly when you need to read the value of the data on your wire. You need to figure it out for yourself. The opposite case is "synchronous serial" where a separate line, usually called the clock line, tells you exactly when to read the data line. It does that by transitioning from one state to another.

Other examples of asynchronous serial protocols include 1-Wire, CAN, UNI/O, and Manchester.

Examples of synchronous serial protocols include SPI, I2C, and Async Serial/PCM.

How Do I Use RS-232 Serial with a Microcontroller?

Is Async Serial on the Way Out?

RS-232 is on the way out. But serial, since it is just so simple and useful, is not going anywhere in the foreseeable future. In addition to logic-level serial used with microcontrollers, there are more functional serial communication links such as RS-422.

Async Serial in a USB World

An Example of Receiving Serial Data on a Microcontroller

Let's take a moment to look at how we would pull off reading serial if we didn't have a fancy serial peripheral (or the boss says we need to use a dirt-cheap $.10 microcontroller that doesn't have one).

To make things simple, we'll assume that our function is called when the bus is idle (not right in the middle of some serial data).

An Example of Receiving Serial Data on a Microcontroller

U8 GetSerialByte()

{
    U8 serial_byte = 0;  //we'll save our result here.
    U8 i;

    while ( serial_input == high );  // wait until the start bit

    wait( 1.5_bit_periods ); // wait until we're in the middle of the first bit.

    if ( serial_input == high )

        serial_byte |= 0x80;

    //if the first (in our case least signifincat) bit is high, 

    //we'll need to set the most significant bit.

    //we'll be rotating this to the right, so this bit will 

    //eventually be in the least significant position

    for ( i = 0; i < 7; i++ )

    {
        serial_byte >>= 1; // shift your result byte to the left by one.  

                           // We'll do this a total of 7 times.

        wait( 1_bit_period );

        if ( serial_input == high )
            serial_byte |= 0x80;

    }

    //we could also check the stop bits, to see if there is a framing error.

    return serial_byte;
}

When doing this sort of thing in code, be aware that all operations such as looping, testing bits, setting bits, and so on take time. Note that in the sample above, we have branches that take different amounts of time, depending on conditions. We would want to balance that:

if( serial_input == high ) serial_byte |= 0x80; else serial_byte |= 0x00;

Even though the 2nd operation does nothing, it will burn the same amount of time as in the opposite case.

If you use loops for timing (they usually do not behave ideally), there will be an extra delay in the call and return, for instance.

While you can, in principle, use the microcontroller's data sheet to exactly predict the timing everything takes, it generally is easier to tweak your algorithm using a logic analyzer. For example, you could toggle a pin whenever you read the serial input. You could then look at this pin and compare it with the real serial data, tweaking where needed to make the timing perfect. When you take out the pin toggle code, you'll want to replace it with some NOPs that take the same amount of time. (Or you can leave it in but change it to operate on a pin that doesn't really exist.)

What Are the Settings for the Saleae Serial Analyzer?

Bit Rate

You can figure out what the bit rate is by recording some data and then measuring how wide the stop bit is.

In the example above, the pulse width of a single bit is measured at about 0.104ms. That is the "bit period," or how long each bit is on the bus. Taking 1/period gives us the frequency and, in this case, yields 9592 bps (ah hah! probably 9600 bps is what they're going for).

Once you know the bit rate, you can enter it into the serial analyzer settings.

Common Serial Bit Rates

You may notice that there are a lot of serial bit rates that seem very common, such as 9600 bps. This is a legacy of the early serial controllers and reflects the various multiples they were able to produce with their hardware—300, 1200, 9600, 14400, 28800, 57600, 115200. These probably ring a bell. You don't need to limit yourself to these, however; any bit rate is fine. The main thing is that the devices agree to use the same bit rate.

Bits per Transfer

Bits per transfer is usually 8, as you might imagine. However, custom serial implementations could easily use a different number of bits per transfer, such as 16 or 32.

Stop Bits

The only thing the Saleae analyzer does with the stop bits setting is check for framing errors.

Parity Bits

If your application uses the parity bit, here's where you can specify whether the Saleae serial analyzer should check for an even or odd parity. The analyzer will report parity errors if they occur.

Bit Order

You can specify if bits arrive—most significant bit first or least significant bit first.

Inverted

Sometimes, serial can be inverted logic high means 0 and logic low means 1. If the data look like the idle level is low (rather than the more common high), then it might be inverted.

MP Mode

MP Mode (also called multiprocessor mode, muti-drop, or 9-bit serial) is a version of serial where the most significant data bit (almost always the last bit) indicates if the preceding 8 bits are data or an address.

Serial Data as Displayed on Saleae Logic Analyzers

Sampling Dots

Little white dots are displayed at the location where the analyzer thought they were the correct locations to sample the bits. If that doesn't appear to be lined up properly with the bits, it’s most likely that the sample rate setting doesn't match the real data.

Error Dots

If there is a framing error or parity error detected, a red dot will appear where the data were sampled, and the text in the bubble will indicate what the error is.

Further Reading

Top Resources

Example Async Serial Parts

What Logic Decodes

  • Start Bit

  • Data Bits

  • Parity Bit

  • Stop Bit

  • Autodetect Baud Rate

RS-232 voltages will probably damage your microcontroller and won't work in any event. You have to convert it. The MAX232 IC (such as ) (and its many variants) is a good way to do it. There are other ways as well. There are also many adapter modules you can buy such as:

USB has almost entirely replaced RS-232 and the associated DB-9 and DB-25 connectors on the back of PCs. However, because serial is so easy to use (especially compared with USB), many USB adapters have been created, both providing RS-232 as well as logic-level serial. Remember, RS-232 voltages will probably damage your microcontroller and won't work anyway, and you have to convert it. The MAX232 IC (such as ) (and its many variants) is a good way to do it. Here are some other adapter modules you can buy:

Bit rate is the number of bits per second being sent. Note: This is also often called baud rate, but that is a term that actually is more relevant to modems and typically misused. It does not actually mean bits per second ().

http://www.sparkfun.com/products/316
http://www.sparkfun.com/products/449
http://www.sparkfun.com/products/8780
http://www.sparkfun.com/products/316
http://www.sparkfun.com/products/8531
http://www.sparkfun.com/products/718
http://www.sparkfun.com/products/10270
http://en.wikipedia.org/wiki/Baud
Tal Tech Tutorial
SparkFun Tutorial
Wikipedia
Parallax Textbook PDF
MAX3232 Breakout
USB to Serial Breakout Board
USB to RS232 Cable