UART protocol analysis

1. Basis of agreement

1.1. Introduction to the Agreement

UART is “Universal Asynchronous Receiver/Transmitter”, short for Universal Asynchronous Transceiver. In the 1860s, to solve the problem of computer and teletypewriter communication, Bell invented the UART protocol, which converts parallel input signals into serial output signals. Because of its simple and practical nature, UART has become a very widely used communication protocol. The serial ports we are exposed to daily, RS232, RS485 and other buses, the internal use is basically the UART protocol.

In order to better understand and analyze the relationship between protocols and buses, we usually divide a complete communication specification into physical layers, protocol layers, and application layers. The physical layer only defines the true signal characteristics (such as voltage, current, driving capacity, etc.), and the correspondence between the electrical signal and the logic signal 0 and 1; The protocol layer does not care about how the underlying 0s and 1s are implemented, but only specifies the protocol specifications of the logical signals and the communication process (such as start, data, and end, etc.); The application layer does not care about how the data is obtained, but only defines the meaning of the data representation and how to implement the specific business logic.

The simplest application of the UART protocol, usually the physical layer only needs two transmission lines, one for transmission and one for receiving, thus achieving full-duplex communication. For one-way transmissions, you can also use only one transmission line. The most typical example of such an application is the microcontroller’s RX/TX ports connected to each other, enabling TTL level-based UART communication. For different transmission distances and reliability requirements, replacing different physical layer implementations can obtain our common RS232, RS485 and other communication buses.

1.2. Different physical layer implementations

Since the input to the UART protocol layer is a logic 0/1 signal, the logic 0/1 signal can be distinguished by different level standards in the physical layer. For different communication needs, different physical layers can be used. For example, simple on-board communication, or common device debugging scenarios, the UART protocol communication between two devices can be carried out using a simple LVTTL/TTL level.

The universal serial port uses the RS232 level, which can increase the transmission distance and resist a certain degree of signal interference. The cost is that the corresponding level translation chip is required at the physical layer to achieve, the transmitter needs to convert the internal high and low level signal into a higher voltage +/- voltage signal, and the receiving end needs to convert the +/- voltage signal into an internal high and low level signal.

In the case of industrial communication, in order to further improve the transmission distance and enhance the reliability of the signal, the RS485 level standard is generally used. The ordinary high and low level signals are converted into a pair of differential signals at the transmitting end, and the differential signals are converted into ordinary high and low level signals at the receiving end. In addition, the RS485 allows up to 128 transceivers to be connected on the bus, while TTL or RS232 are point-to-point connections.

1.2.1. TTL-based UART communication

UART communication based on TTL is the simplest use case for UART protocol applications. That is, the high and low levels of the digital I/O output are directly transmitted as the actual physical signal. In terms of physical connection, only the device needs to be common ground, and one-way device communication can be completed through a signal line. If bidirectional full duplex is required, two signal lines are used.

To compare the differences in the implementation of different physical layers, we can observe how the actual signals of different physical layers differ when the same data is sent. Here, taking the transmission character ‘D’ as an example, through the stone oscilloscope, directly observe the signal transmitted by the TTL (the probe ground terminal is connected to the common ground end of the device, and the probe signal end is connected to the blue signal line in the figure above), and the signal waveform shown in Figure 1-4 can be obtained. As can be seen from the waveform, when there is no data transmission, the UART signal will remain at a high level (the specific signal amplitude is determined by the supply voltage of the I/O), the signal will jump during the data transmission, and the signal will return to the idle high level state after the transmission is completed.

1.2.2. UART communication based on RS232

In order to enhance the drive capability to increase the transmission distance and reliability, the RS232 bus uses a bipolar voltage signal for physical transmission. Before the signal is sent/received, the internal signal and the bus signal are converted to each other by means of a level shifting chip. The connection method is exactly the same as the TTL level, and the entire physical layer is just one more layer of level translation.

Also using the transmit character ‘D’ as an example, the probe of the Pushi oscilloscope is connected to the signal end and the actual waveform shown in Figure 1-6 can be captured. It can be seen that the RS232 waveform is negative voltage when idle, and when there is data transmission, the signal begins to jump between positive and negative voltages, and returns to the idle negative voltage state after the transmission is completed.

1.2.3. UART communication based on RS485

The RS485 is designed for complex industrial environments, and the biggest feature of the RS485 bus is the use of differential signal transmission compared to the physical layers of other UART protocols. Before the signal is sent, the single-ended signal is converted into a differential signal by the transceiver of RS485, and then sent to the bus for transmission; Also before receiving, the differential signal on the bus is converted by the transceiver into a single-ended signal and then sent to the UART controller for reception. On the RS485 bus, two pairs of differential signal lines (i.e. 4 signal lines) are required for full-duplex bidirectional communication. If only half-duplex two-way communication is performed, only a pair of differential signals is required.

Again, using the transmit character ‘D’ as an example, the actual waveform shown in Figure 1-8 can be acquired using two channel probes (commonly referenced) of the probes of the Pushi oscilloscope, which are connected to the A/B ends of one of the differential signals. It can be seen that the waveform at the A/B end is complementary. The A-terminal waveform is forward logic (positive voltage when idle) and the B-terminal waveform is reverse logic (negative voltage when idle).

2. Protocol Specifications

2.1. UART frame structure

In the introduction of the previous section, we observed the actual UART waveform through the stone oscilloscope, so how exactly is this waveform accurately recognized as the character ‘D’ and not something else? This involves the definition of the frame structure of the UART protocol. As shown in Figure 2-1:

When two devices need to communicate via the UART protocol, they need to agree on the following at the same time:

  • Length of time per signal T (baud rate = 1/T)
  • The specific number of bits in each item in the frame structure
  • Whether there is a check digit, and the mechanism of the check digit (odd/even/…). )

With these conventions, the receiving device only needs to wait for the arrival of the starting bit, and then sample the subsequent waveform at regular intervals to obtain the specific information transmitted. Taking the waveform of the character ‘D’ as an example, the resolution process is shown in Figure 2-2:

2.1.1. Baud rate

Baud rate is a very important concept of the UART protocol, or all asynchronous serial protocols, that is, the number of bits that can be represented per unit time (1 second), or it can also be expressed as the reciprocal of the bit width. For example, a UART waveform with a baud rate of 115200 means that it can accommodate 115200 bits per second, which means that each bit of data accounts for about 8.68uS of time.

Asynchronous serial protocols such as UART, in order to simplify the physical connection of signals and reduce communication costs, generally have only one signal line, and cannot transmit data and clock signals at the same time. In order for the transceiver/transmitting device to correctly resolve the waveform, it needs to be at the same baud rate setting. The same waveform using different baud rates may obtain completely different information. For the receiving device, only the start bit can be used as the synchronization point of a frame of data, and the other data is determined by the baud rate to determine the specific sampling location.

Again, using the waveform of the character ‘D’ as an example, as shown in Figure 2-4, if it is received at the wrong baud rate, you may get completely wrong data information.

2.1.2. Idle Bits

When data is not transferred between devices, a sustained high level indicates idleness. The longer the idle bit duration and the longer the interval between two data frames, the less data is transmitted per unit time.

2.1.3. Start Bit

The UART receiver will always detect the level change on the signal line, and when the data is transmitted, the sender will pull the signal line from the high level to the end of the low level to idle state, and maintain a bit of time. When the receiver detects a high-low level shift, it starts receiving signals.

2.1.4. Data Bits

The data bit contains the actual data transmitted, which is 5 to 8 bits long if parity is used, and 5 to 9 bits if parity is not used. In general, the data bits are 8 bits, and the data is sent first from the least significant bit, with the high bits coming second.

2.1.5. Check digits

The check digits can be used to improve the reliability of the transmission. If the signal is wrong due to interference in the transmission process and causes an error in the level of some positions, it can be determined whether the data received and the check digit match by calculating whether the received data and the check digits are matched, so as to provide valid information to the application layer to decide to accept/discard the corresponding data.

2.1.6. Stop Bit

The stop bit represents the end of a frame of data, and the actual signal is a period of time high. The length of the stop bit can be set to a stop bit of 1, 1.5 or 2 bits. In most cases, a stop bit of 1 bit is used.

Because UART is an asynchronous protocol, the beginning of each frame can be synchronized with a jump edge, but the stop bit can only calculate the relative position by the baud rate, and if a low level is recognized at the stop position, a frame error is generated. In the communication process, in order to reduce the problem caused by the error of the baud rate, different stop bit lengths can be set to adapt.

3. Analyze UART communication using a logic analyzer

3.1. Oscilloscope vs Logic Analyzer

As the main general-purpose test and measurement instrument, oscilloscopes have a natural advantage in observing the details of analog signals. For example, real-time operation, with a high waveform refresh rate, can easily observe sudden abnormal signals; For example, when performing noise evaluation and signal quality optimization, the oscilloscope can compare the similarities and differences of signals on the same bus and different nodes to find hidden signal integrity problems.

However, the oscilloscope also naturally has some inconvenient places, in addition to the few channels, the screen is generally small, the operation is not computer + mouse way flexible and controllable these morphological problems, for the acquisition and analysis of digital signals, the biggest problem of the oscilloscope is that the storage depth is too small. An oscilloscope of several hundred thousand yuan may also have a storage depth of only a few hundred Mpts. At the same time, because of the limitation of the storage depth, when it is necessary to do a slightly longer time acquisition, the true sampling rate of the oscilloscope will drop sharply, resulting in the collected waveform cannot restore the real signal, losing the significance of analysis.

Logic analyzers are test and measurement instruments specifically designed for digital signal acquisition and analysis, and the waveform results collected are only high and low levels (that is, logical 0 and 1). However, it makes up for the lack of oscilloscopes in acquiring and analyzing digital signals.

  1. 1. Most logic analyzers are operated on a PC, with the powerful performance of desktop processors and the interactive experience of mature operating systems, which greatly improves the convenience and efficiency of digital signal analysis.
  2. 2. The number of logic analyzer channels is large, the entry-level DSLogic logic analyzer has 16 channels that can be collected at the same time, and the user can also obtain logic analyzer products with dozens or even hundreds of channels at a very reasonable cost.
  3. 3. The storage depth of the logic analyzer is larger, for example, DSLogic can reach a storage depth of 16G in stream mode, and at the same time maintain a fairly high sample rate, far exceeding the acquisition capability of most oscilloscopes.
  4. 4. Logic analyzers generally provide rich protocol decoding functions, which can perform in-depth analysis of digital signals. For example, DSLogic currently supports more than 100 decoding protocols. Most oscilloscopes have limited decoding capabilities, and most require the corresponding plug-ins to be purchased separately.

Next, we will focus on how to use logic analyzers for the acquisition and analysis of UART signals in various situations.

3.2. Establish a test environment for logic analyzers

3.2.1. Connection to DSLogic

DSLogic is a portable logic analyzer based on USB connectivity. The DSLogic host is responsible for signal acquisition and caching, and then transmits the data via USB to the host computer software DSView on the PC. DSView is responsible for waveform data processing, display, analysis, and corresponding human-computer interaction functions.

When using, simply connect the DSLogic host directly to the USB port on the PC board via a USB data cable, open the DSView software, and confirm that the INDICATOR on the DSLogic host becomes evergreen. At this point, the connection and initialization of the logic analyzer is completed. As shown in Figure 3-4, the current device name in the upper left corner and the corresponding connection status can be observed on the DSView software.

3.2.2. UART signal connection

For all measurements, the test equipment and the signal to be measured must be based on a common reference plane, which is commonly referred to as grounding, so that the measured signal can be correctly acquired and measured. In some cases, there is no explicit grounding, but the measurement results seem to be no problem, this is because the measurement equipment and the measured signal are connected to the ground in other ways, such as the same power supply used, or the reference ground is connected to the ground terminal of the mains at the same time. However, when making rigorous measurements, the measuring equipment should be grounded according to the signal under test. The larger the loop area of the signal grounding terminal from the measured signal to the measuring device, the easier it is for the signal to be interfered with, resulting in measurement errors or even measurement errors.

For UART signals, when accessing the logic analyzer, the simplest case only needs to connect 2 wires, one to the reference ground, and one to the measured signal. For the different physical layer implementations of the UART protocol we mentioned earlier, the way the signals are connected will be slightly different.

For example, for the UART signal at the TTL level, in addition to connecting the reference ground, only need to connect the signal (TX or RX) to be tested to the corresponding channel input of the logic analyzer.

For RS232 bus signals, we can either measure the bus signal after level translation (DSLogic has a withstand voltage range of +-30V at the cable input, and the +-15V signal range of RS232 can be directly connected), or we can measure the internal digital signal before level translation. Its wiring method is consistent with the TTL signal, the only thing to note is that the RS232 signal flips the level (negative voltage when idle, that is, low level), when decoding the UART protocol, we can reverse the corresponding signal level in the decoding setting window of DSView (Invert Signal option is set to yes).

The RS485 bus uses differential signals, and when we use a logic analyzer for signal acquisition, we need to pay special attention to the connection of the measured signal. First of all, the reference site of the logic analyzer needs to be connected to the reference ground of the corresponding device under test RS485 transceiver, so that the logic analyzer can be guaranteed to have the correct level reference plane; Second, for differential signals, the logic analyzer only needs to acquire high and low levels of homopolarity with the internal signal. From the perspective of digital signals, the differential way only improves the reliability of signal transmission, without adding additional information. As shown in Figure 3-7, when testing the 485 bus signal using a logic analyzer, connect the reference ground of the transceiver of the corresponding device and the A+ signal on the differential bus.

Of course, if only the B-signal can be collected, we can also set the UART decoder to reverse the signal to obtain the correct protocol resolution result when decoding in DSView.

3.2.3. Threshold Settings

The threshold of the logic analyzer is the judgment voltage of high and low levels, that is, when the input signal voltage is higher than the threshold voltage, the acquisition is high level; When the input signal voltage is below the threshold voltage, the acquisition is low.

For the UART protocol, we have previously introduced that it has different physical layer implementations, and different physical layer implementations have different level standards. We only need to choose a corresponding threshold to distinguish between high and low levels in different cases. The thresholds shown in Figure 3-8 can basically meet this requirement.

In some cases, the differential signal amplitude of the RS485 bus may vary over a wide range due to configuration or debugging. Because the RS485 specification stipulates that as long as the differential voltage between A-B is greater than 200mV, it can be considered high. At this point, we can use the stone oscilloscope to observe the actual signal level amplitude and then decide on the appropriate threshold setting. You only need to make sure that the threshold voltage you set can reasonably distinguish between high and low levels.

3.3. Simple UART signal acquisition

Most UART signals are low-speed signals, such as the most commonly used baud rate of 115200, indicating that the signal frequency is only 115.2KHz. Such signals can be acquired directly using the default settings of DSLogic. Here, taking the host fixed 1s interval and repeatedly sending the character ‘D’ as an example, it describes how to use a logic analyzer to acquire and analyze such UART signals.

3.3.1. Signal Acquisition

After the hardware and signal connection are prepared, click the “Start” button of the DSView software directly to acquire the signal under test at the default setting (1MHz sample rate acquisition time 1s). If you want to modify the sample rate and acquisition duration, select the corresponding parameters directly in the corresponding drop-down box. The sampling rate setting principle is recommended to be 10 times or more of the maximum frequency of the measured signal, for example, for UART signals with a baud rate of 115200 baud, the fastest signal frequency is 115.2KHz, when the 1M sampling rate is selected, each bit signal will have 8 or 9 sampling points, and the corresponding phase error is +-1/8 (12.5%); When a 10M sample rate is selected, there will be 86 or 87 sample points per bit of signal, corresponding to a phase error of +-1/86 (1.16%). Of course, it is generally not recommended to use too high a sample rate, because the higher the sample rate, the shorter the time for which it can be collected, and the sample rate that is too high may collect multiple jumps on the single jump edge of the slow signal, thus causing trouble to the protocol decoding. Figure 3-9 shows the resulting signal waveform acquired using the default settings.

As can be seen from Figure 3-9, Channel 0 acquires a signal that is persistently high, but does not find any jumps. Carefully observe the time ruler above the waveform window and the scroll bar at the bottom of the window to know that the current window displays only part of the collected waveform, not all signals. At this point, you can zoom by the mouse wheel or right-click in the waveform area to display all waveforms for the entire acquisition duration. Get the result shown in Figure 3-10.

On the basis of the above figure, we want to look only at the transition part of channel 0. You can turn off the waveform display of other channels in the Options window and adjust the display height of the channel signal. Then point the mouse at the target waveform, and at the same time through the mouse wheel to enlarge the waveform of the pointed position; Alternatively, you can select the area of the waveform you want to zoom in by holding down the right mouse button in the box. Also, hold down the left mouse button to move the waveform left and right. Get the waveform details shown in Figure 3-11.

When observing the waveform, placing the mouse over the pulse waveform can display information such as the pulse width, period, frequency, and duty cycle of the current signal. At the same time, you can also add a cursor by double-clicking the left button of the mouse, and when you move the cursor, it will automatically snap to the nearby jump edge.

3.3.2. UART decoding

The signal waveform collected by the logic analyzer only changes in time at high and low levels (0/1), which is not conducive to our targeted analysis of the process and content of signal transmission. Although we can use the naked eye to translate the protocol content corresponding to the waveform according to the protocol specification, it will greatly reduce the efficiency of the analysis. DSView’s built-in decoder provides rich protocol decoding content, turning boring waveforms into meaningful characters, markers, and data content. It greatly facilitates the analysis and understanding of signals by engineers to find error messages or critical data.

In the DSView software, the protocol decoding of the acquired waveform is very simple, just open the “Decode” panel, search for the corresponding decoder (here we select 1: UART protocol), and set the corresponding decoder options (including display/channel/frame structure/format, etc.). Once determined, the software will begin to decode the protocol of the UART on the selected channel. The decoded result is displayed in the protocol channel. This is shown in Figure 3-12.

When selecting a decoder, DSView provides a convenient protocol search function, just enter key characters in the protocol search box, DSView will list all the decoders containing these characters, where the user can select the correct decoder. As shown in Figure 3-13, there are two protocols related to UART 0: UART and 1: UART, where 0: UART is a simplified decoder that does not parse bits information, nor does it support the stacking of higher-level protocols, when we only want to get the data corresponding to the waveform, You can use this simplified protocol to reduce decoding time and memory resources.

The settings window of the decoder has many setting options related to decoding, and the contents of the settings window of different protocols will be different. There are some options that all decoders must set, such as the correspondence between channel and protocol signals. Here we are using the UART signal grabbed by channel 0, so the corresponding channel that needs to be decoded should be set to channel 0.

And protocol-related setting options we have explained in detail in the frame structure section, in the actual operation can also be obtained through the serial port host computer software (serial port debugging assistant, etc.) to obtain this information. This is shown in Figure 3-14.

For decoded data content, DSView supports different display formats. For example, the previously acquired UART signal displays the character ‘D’ in the form of ASCII codes, or it can be modified to the display mode of hexadecimal (Hex), and the result will display 0x44. This is shown in Figure 3-15. Currently supported display formats are: hex (hexadecimal), dec (decimal), oct (octal), bin (binary) and ascii code.

3.4. Acquisition of a single UART transmission

When the waveform we want to capture is an occasional signal, we do not know when the waveform will appear, and if we use the direct acquisition method, we may only be able to capture the idle signal waveform most of the time, and we cannot capture the signal at the time of actual transmission.

At this time, it can be captured by triggering. By setting the corresponding trigger conditions, we can control the start time of signal acquisition according to the change of waveform, so as to accurately capture the signal waveform we want to see.

3.4.1. Buffer mode

DSLogic supports two acquisition modes: Stream mode and Buffer mode. The data collected in Stream mode is transmitted to the PC in real time and then processed by DSView. The data collected in Buffer mode is first cached in DSLogic’s internal hardware cache, and then transferred to the PC after the acquisition is completed, and processed by DSView.

In addition to the advantages of achieving higher sample rates, Buffer mode also supports more triggering options and settings, such as multi-level triggering, serial triggering, and setting of trigger positions. Stream mode, on the other hand, only supports simple triggering.

3.4.2. Trigger Settings

For simple triggering, we can set the trigger option directly next to the channel. It corresponds sequentially to rising edge, high, falling edge, low level, and any edge trigger. Just keep the default simple trigger mode in the trigger panel. For example, for a UART transmission that does not know when it occurs, we can choose to trigger the falling edge. When the UART signal remains idle, the trigger is not satisfied. DSLogic waits for the trigger condition to arrive, as shown in Figure 3-17.

When the UART starts transmitting the first start bit, the trigger condition is activated, and DSLogic acquires the signal waveform at the time of the trigger. This is shown in Figure 3-18.

Let’s consider a more complex trigger scenario, such as device A constantly sending data to device B at random, and device B replying to different data according to the data content sent by device A. If we want to know what data Device A sent to Device B before sending data 0, how do we set the trigger condition to catch the waveform at the corresponding moment?

There are two problems that need to be solved here, first we need to set the location of the trigger so that we can see the data before the trigger, not the data after the trigger; Second, we need to find the waveform characteristics of device B sending data 0 and convert it into the corresponding trigger condition.

UART protocol analysis

Figure 3-19 Trigger position

According to the protocol rules of UART, the waveform that sends data 0 will be a relatively wide continuous low-level pulse signal. If the baud rate of the UART is 115200 and the sampling rate we set is 1MHz, the waveform of data 0 is shown in Figure 3-20, which will be a low-level pulse of about 78.125uS.

To set the advanced trigger or trigger position requires buffer mode support, you need to first set the “Run mode” to “Buffer mode” in the “Options”, and do not select the “RLE hardware compression” option. Set the advanced trigger condition to channel 1 with a continuous low of 75 sample points (corresponding to a 1MHz sample rate, which is a low level of 75us), and set the trigger position to 80% to facilitate the observation of data before triggering. The specific settings are shown in Figure 3-21.

According to this trigger condition, it is triggered when device B sends data 0, and the acquired waveform is shown in Figure 3-22.

3.4.3. Repeat the collection

In some cases, we need to dynamically observe the status of some signals, such as the data content sent by Burst every time, but we don’t know when the data is sent, and it is impossible to click the “Start” button frequently. DSView provides a “repeat” acquisition mode that automatically acquires and updates waveforms when triggering is met. When we debug some periodic burst signals, it is very convenient to observe the results of dynamic acquisition and protocol parsing through the repeat mode.

The repeat mode can be set as shown in Figure 3-23. The repetition interval is the minimum dwell time between two samples to facilitate the observation of the waveform and decoding results of the previous acquisition.

3.5. Acquisition of long-term UART transmissions

When it is necessary to acquire ultra-long waveforms for analysis, we can use Stream mode. DSLogic can achieve a sampling depth of 16G per channel in Stream mode. At a sampling rate of 1MHz, the acquisition time can reach 16G/1M ≈ 16000s, which is more than 4 hours.

3.5.1.Stream mode

The Stream mode setup is shown in Figure 3-24, and different DSLogic hardware versions support different stream mode channel options. For U3Pro16, based on the USB3.0 port, it can achieve 3 channels @ up to 1GHz sample rate, 6 channels @ up to 500MHz sample rate, 12 channels @ up to 250MHz sample rate and 16 channels @ up to 125MHz sample rate.

When the amount of data collected is relatively large, the 0:UART protocol can be used for decoding, compared with 1:UART, which omits the output of bits information, does not support high-level protocol stacking, and can shorten the decoding time and reduce memory occupation. The other functions are the same as 1: UART. The decoding effect is shown in Figure 3-25.

3.5.2. The list of protocols is displayed

As shown in the following figure, the graphical decoding result is completely synchronized with the acquired waveform in time, which helps us understand the waveform and find the problem, but at the same time, because of the display scale of the time, it is not conducive to viewing the decoding result. List displays make up for this shortcoming, making it easy to view and analyze large amounts of decoded content.

DSView provides a way to jump between graphical and list results. Click any row in the list results to automatically jump to the corresponding waveform result, and you can also choose whether to automatically zoom in on the waveform when jumping, or fix the current zoom ratio column of the waveform. In addition, when we view the waveform at a certain moment, if we want to jump to the position where the decoding result corresponding to this waveform is displayed in the list, you only need to click the positioning button in the upper right corner of the list display window.

In addition, the decoded content can be exported to a file through the list display. As shown in the figure above, clicking the “Save” button displayed in the list, you can choose to export the currently decoded content to a csv or txt file, which is convenient for more third-party data processing, such as input to matlab for analysis, or as data input for other software.

3.5.3. Decode data search

Another advantage of the list display is that the decoded results can be used as strings for results searches, such as searching for specific operations, or specific bytes of data, which can quickly locate the location that needs to be viewed.

Enter the keyword you want to search for in the search box, then press the forward/backward buttons to find the decoded content that contains the keyword, and the waveform interface will jump to the appropriate location for analysis. If you are parsing the results of a segment, you can click a row in the checklist, and the Forward/Backward buttons look for the previous and next matches starting with this behavior instead of starting from scratch.

For the UART protocol, DSView also supports multi-row data search. Can be used to find some contiguous string results that appear in your data. As shown in Figure 3-29, a multiline data search concatenates multiple keywords with the “-” character.

3.5.4. Waveform Search

DSView supports not only the search of decoded results, but also the search function of the original waveform. Waveforms can be quickly located in many scenes. For example, when the waveform is transmitted suddenly, because the idle period is relatively long, it is impossible to see the detailed waveform transmitted multiple times at the same time, you can use the waveform search, and immediately jump to the next waveform jump after viewing the waveform at the previous moment to ensure that the zoom ratio is unchanged.

Check the “Search” toolbar, the search box will appear below the software window, click the search box, pop up the search settings window, determine the channel jump edge, you can search for the waveform that meets the criteria by the left and right keys. At the same time, you can also manually move the search cursor to determine where the search starts.

When search is selected, a cursor with an “S” tag appears, the initial state is gray, if you click left/right to search and find a waveform that meets the criteria, the cursor will turn blue and automatically move to the search location. If you manually move the “S” cursor, the cursor turns gray again.

3.5.5. Cursor Usage

DSView supports a wide range of cursor operations, allowing not only timing measurements with the cursor, but also marking and tracking special waveforms with the cursor. When the waveform is idle or the interval is long, you can insert a cursor at each position of interest, and when you want to jump to a waveform of interest, you only need to right-click in the ruler area, and then click the cursor sequence number you want to jump to, which can jump to the corresponding cursor position.

If you want to move the cursor, you only need to move the mouse near the cursor, when the cursor appears bold, click the left mouse button to select, the cursor will follow the mouse movement, determine the position and click the left button again to release the cursor. When you want the cursor to snap to one of the jump edges of a particular channel waveform, you only need to move the mouse near the jump edge, and the cursor will automatically snap to the edge of the jump.

3.5.6. Mouse measurements

In addition to cursor-based measurements, DSView provides more convenient mouse measurements. For example, measurements of current pulse width, period, duty cycle, and frequency (just need to place the mouse over the changing pulse); Measurement of the number of edges (clicking on the start and end positions on the waveform will automatically count the jump edges of this interval); and measurement of the edge distance (mouse click on the starting edge and move to the end edge).

As shown in Figure 3-31, move the mouse to the position of the starting transition edge, click the left mouse button, select the starting transition edge, move the mouse to the position of the end transition edge, and the distance between the two transition edges (duration/sampling interval point) will be displayed, and the left mouse button will be clicked again to complete the measurement.

4. Frequently Asked Questions

4.1. Determine the unknown baud rate

When we cannot obtain the baud rate of the UART waveform in advance, we can also guess the true baud rate by the acquired waveform. DSView provides a “Guess bitrate” decoder to guess the baud rate parameters of an arbitrary waveform string. The principle of Guess bitrate is to find the narrowest pulse width in the waveform in turn, as the waveform width of a bit, and then calculate its reciprocal as the baud rate. So there may be multiple results, we only need to observe whether the corresponding pulse is a reasonable pulse width, and then select the maximum baud rate result. This is shown in Figure 4-1.

Once the baud rate is obtained, it can be set to the options for the UART decoder. Because the UART protocol resynchronizes each start bit, the error of the baud rate will only accumulate in one frame of data, and as long as the error within one frame does not exceed the boundary of the bit bit, the correct decoding result can be obtained.

Of course, if there is a small sample of the waveform, such as no pulse of a single bit width in the waveform, then the guessed baud rate is likely to be incorrect, resulting in an incorrect decoding result. When there is a waveform that does not conform to the protocol, the UART decoder will also give possible error hints, such as frame error, as shown in Figure 4-2. Experienced engineers can adjust the baud rate by observing the waveform and decoding results in order to obtain the correct decoding results.

4.2. Decoding of anti-confidence signs

In the previous section we mentioned that the UART protocol can be transmitted by different physical signals, and some physical layer signals may have an inverse relationship with the protocol signal (high and low level interchangeable), such as RS232, or the B-signal in the RS485 differential signal. When the signal we collect is reversed, DSView’s UART decoder can also be set to obtain the correct decoding result.

The user only needs to replace the “Invert Signal ?” in the settings of the UART decoder. The option is set to “yes”. The decoding of the reverse signal is shown in the following figure.

4.3. Decoding of multi-group UART communication

DSView’s UART decoder is deliberately designed to be a single-channel approach, which facilitates arbitrary channel settings for multiplexed communication when decoding. For example, for a full-duplex UART communication, which has both a TX signal and an RX signal, we only need to add two UART decoders to correspond to the decoding of TX and RX.

As shown in the figure below, it is the case where three UART signals are decoded at the same time.

4.4. Decoding error caused by the starting position

For any communication process, the device must start from the initial state in order to correctly receive the communication content, that is, correctly identify and analyze the protocol frame. The same is true for logic analyzers, if the acquisition of a signal starts exactly in the middle of a frame of data, then the wrong starting position is likely to lead to a wrong decoding result. As shown in the following figure, the device keeps sending the string “DreamSourceLab”, but because the location of the first capture is exactly in the middle of the data frame, the decoding of the first waveform becomes garbled.

In order to avoid incorrect decoding of data, we can artificially set the starting position and end position of decoding, so as to avoid decoding errors caused by truncated data frames. The decoding position can be the specified position of any cursor, and the operation only needs to set the corresponding starting and ending positions in the settings of the decoder after inserting the corresponding cursor. As shown in the following figure, setting the starting position avoids incorrect decoding of the first truncated waveform.

5. Advanced analysis

5.1. Multi-layer protocol parsing

UART is a very widely used base protocol, and many of the transmission protocols used in practical applications are extended on the basis of UART. For example: DMX512, LIN, MIDI and Modbus, etc., the underlying communication basis is the UART protocol. 、

According to this feature, DSView also supports the parsing stacking of multi-layer protocols. When we add a decoder of a complex protocol, DSView will automatically build the entire protocol stack from the top level, which makes the decoding results richer and more perfect, which is very helpful to the user’s in-depth analysis and understanding of the protocol.

Let’s take Modbus RTU as an example to understand the process of DSView analyzing multilayer protocols. Based on the UART byte transfer function, Modbus RTU specifies the specific meaning of each byte in detail, so that the frame structure of Modbus is formed by combining multiple UART protocol frames together. This is shown in the following figure.

When using DSView for such protocol decoding, you only need to enter the corresponding protocol in the protocol search box and add it. DSView automatically builds the settings page for the entire stacking protocol, as shown in the following figure, and the user can make the corresponding settings.

As shown in the following figure, the stacking structure of the protocol can be clearly seen from the decoding result of the Modbus RTU. The Modbus for each frame consists of 8 UART byte frames. The content of a Modbus frame will also have clear comments indicating its specific meaning. When a transmission error occurs, such a decoding result can very clearly locate the location of the error, as well as the cause of the error (whether it is a problem with the underlying UART or a problem with the Modbus protocol layer). If you do not want to see the underlying details, you can hide the corresponding decoded content on the settings page of the decoder.

Be the first to comment

Leave a Reply

Your email address will not be published.