Wiki

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
university:courses:electronics:m2k-uart-debug [26 Mar 2019 16:50] Antoniu Miclausuniversity:courses:electronics:m2k-uart-debug [03 Jan 2021 22:21] (current) – fix links Robin Getz
Line 5: Line 5:
 The objective of this tutorial is to use the Pattern Generator and Logic Analyzer instruments provided by the [[adi>ADALM2000]] (M2K) board and the [[university:tools:m2k:scopy|Scopy]] software toolset to visualize UART (Universal Asynchronous Receiver/Transmitter) transactions between two devices. The objective of this tutorial is to use the Pattern Generator and Logic Analyzer instruments provided by the [[adi>ADALM2000]] (M2K) board and the [[university:tools:m2k:scopy|Scopy]] software toolset to visualize UART (Universal Asynchronous Receiver/Transmitter) transactions between two devices.
  
-As an example we will use as second device the [[adi>EVAL-ADICUP3029]] microcontroller board and a software project that contains the communication module for UARTbeing able to receive data and transmit it back.+The [[adi>EVAL-ADICUP3029]] microcontroller board and a typical software project that uses the UART communication module, waits for input data from the user, and then echoes it back through the pins available on the board.
  
 ===== Background ==== ===== Background ====
  
-Universal Asynchronous Receiver/Transmitter is a computer hardware device (physical circuit in a microcontroller or a stand-alone integrated circuit) for asynchronous serial communication in which the data format and transmission speeds are configurable. Its main purpose is to transmit and receive serial data, using only two wires to communicate between devices (TX and RX).+Universal Asynchronous Receiver/Transmitter (UART) is a computer hardware device for asynchronous serial communication in which the data format and transmission speeds are configurable. Its purpose is to transmit and receive serial data, using only two wires to communicate between devices (TX and RX). In the past, UARTs were separate integrated circuits, such as the industry standard 16550. However, most modern microcontrollers include one or more UART peripheral devices on-chip, requiring only an external physical interface device, such as a line driver / receiver or USB-UART interface device.
  
-The UART transmit converts parallel data from a controlling device like a microcontroller into serial form, transmits it in serial to the UART receive, which then converts the serial data back into parallel data for the receiving device. Data flows from the TX pin of the UART transmit to the RX pin of the UART receive.+The UART transmitter converts parallel data from a controlling device like a microcontroller into serial form, transmits it in serial to the UART receiver, which then converts the serial data back into parallel data for the receiving device. Data flows from the TX pin of the UART transmitter to the RX pin of the UART receiver.
  
 <WRAP centeralign>{{:university:courses:electronics:uart_flow.png?400|}}</WRAP> <WRAP centeralign>{{:university:courses:electronics:uart_flow.png?400|}}</WRAP>
 <WRAP centeralign>Figure 1. UART data flow between devices</WRAP> <WRAP centeralign>Figure 1. UART data flow between devices</WRAP>
  
-UART transmits data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART. The UART transmit contains start and stop bits to the data packet being transferred. These bits define the beginning and end of the data packet so the receiving UART knows when to start reading the bits.+UART transmits data asynchronously, which means there is no clock signal to synchronize the output of bits from the transmitting UART to the sampling of bits by the receiving UART. The UART transmit contains start and stop bits to frame the data byte being transferred. These bits define the beginning and end of the data byte so the receiving UART knows when to start (and stop) reading the bits.
  
 {{:university:courses:electronics:uart_frame.png|}} {{:university:courses:electronics:uart_frame.png|}}
 <WRAP centeralign>Figure 2. UART data frame</WRAP> <WRAP centeralign>Figure 2. UART data frame</WRAP>
  
-When the UART receive detects a start bit, it starts to read the incoming bits at a specific frequency known as the baud rate. Baud rate is the rate at which data is transferred, expressed in bits per second (bps). Both UARTs (Rx and Tx) must be configured at almost the same baud rate. The baud rate between the transmitting and receiving UARTs can only differ by about 10% before the timing mismatch occurs.+When the UART receiver detects a start bit, it starts to read the incoming bits at a specific frequency, called the baud rate. Baud rate is the rate at which data is transferred, expressed in bits per second (bps). Both UARTs (Rx and Tx) must be configured at almost the same baud rate. This scheme is tolerant of a slight mismatch in baud rate between the transmitting and receiving devices; a typical 8-bit byte can tolerate approximately 10% difference in baud rate between transmitter and receiver before a bit error occurs.
  
-UART transmitted data is organized into packets. Each packet contains 1 start bit, 5 to 9 data bits (depending on the UART), an optional parity bit, and 1-2 stop bits.+UART data is organized into bytes. Each byte contains 1 start bit, 5 to 9 data bits (depending on the UART), an optional parity bit, and 1 or 2 stop bits.
  
 <WRAP centeralign>{{:university:courses:electronics:uart_sequence.png?700|}}</WRAP> <WRAP centeralign>{{:university:courses:electronics:uart_sequence.png?700|}}</WRAP>
-<WRAP centeralign> Figure 3. UART Packet Configuration </WRAP>+<WRAP centeralign> Figure 3. UART Byte Configuration </WRAP>
  
-The UART data transmission line is normally held at a high voltage level when no transmission is occurring. To start the transfer of data, the the transmission line is pulled from high to low. When the receiving UART detects the high to low voltage transition, it begins reading the bits in the data frame at the frequency of the baud rate. +The UART data transmission line is normally held at a high voltage level when no transmission is occurring. To start the transfer of data, the the transmission line is pulled from high to low. When the receiving UART detects the high to low voltage transition, it interprets this event as as start bit and begins reading the rest of the bits in the data frame at the selected baud rate.
  
-Parity describes the evenness or oddness of a number. The parity bit is a way for the receiving UART to tell if any data has changed during transmission. Bits can be changed by mismatched baud rates, long distance data transfers, etc. After the receiving UART reads the data frame, it counts the number of bits with a value of 1 and checks if the total is an even or odd number. If the parity bit is 0 (even parity), the 1 bits in the data frame should total to an even number. If the parity bit is a 1 (odd parity), the 1 bits in the data frame should total to an odd number. When the parity bit matches the data, the UART knows that the transmission was free of errors+parity bit may be included after the data bits. Parity describes the evenness or oddness of a number.
  
-To signal the end of the data packet, the sending UART drives the data transmission line from a low voltage to a high voltage for at least two bit durations.+Even parity: for a given set of bits, the occurrences of bits whose value is 1 is counted. If that count is odd, the parity bit value is set to 1. If the count of 1s in a given set of bits is already even, the parity bit value is 0. 
 + 
 +Odd parity: for a given set of bits, if the count of bits with a value of 1 is even, the parity bit value is set to 1 . If the count of bits with a value of 1 is odd, the count is already odd so the parity bit value is 0.  
 + 
 +The parity bit is simple error detection scheme, and will detect all single-bit errors. Bits can be changed during transmission by mismatched baud rates, noise picked up on long distance data transfers, etc. Like baud rate, both transmitter and receiver must be set to the same parity configuration. 
 + 
 +To signal the end of the data byte, the sending UART drives the data transmission line from a low voltage to a high voltage for at least two bit periods.
  
 ===== Hardware Configuration ==== ===== Hardware Configuration ====
Line 60: Line 66:
   * Pin7 - DIO1   * Pin7 - DIO1
   * Pin8 - DIO0   * Pin8 - DIO0
 +
 +**EVAL-ADICUP3029 UART switch configuration:**
 +
 +  * Set S2 to the CENTER position.
 +
 +(S2 selects which device to connect the ADuCM3029's UART to - USB-UART interface, Arduino headers, or WiFi module connector.)
 +
 +===== Software Configuration ====
 +
 +There are several options for which software to use for this demonstration; the main requirement is that it implement some sort of command-line interface that echoes characters back as they are typed. The CLI example project for the EVAL-ADICUP3029 can be used:
 +
 +[[https://github.com/analogdevicesinc/EVAL-ADICUP3029/tree/master/projects/ADuCM3029_demo_cli|CLI example for ADICUP3029]]
 +
 +
  
 ===== Scopy Pattern Generator Configuration ==== ===== Scopy Pattern Generator Configuration ====
  
-First, we need to setup the Pattern Generator that will be used to transmit data to EVAL-ADICUP3029.+First, set up the Pattern Generator to transmit test data to EVAL-ADICUP3029.
  
 The EVAL-ADICUP3029 software application has the UART configured as follows: The EVAL-ADICUP3029 software application has the UART configured as follows:
Line 89: Line 109:
 ===== Scopy Logic Analyzer Configuration ==== ===== Scopy Logic Analyzer Configuration ====
  
-Several SPI configuration parameters need to be determined in order to properly configure Scopy. For the EVAL-ADICUP3029 project, they are as follows:+Several UART configuration parameters need to be determined in order to properly configure Scopy. For the EVAL-ADICUP3029 project, they are as follows:
   * Baud rate: 115200   * Baud rate: 115200
   * Data bits: 8   * Data bits: 8
Line 109: Line 129:
 <WRAP centeralign> Figure 7. UART Group Settings </WRAP> <WRAP centeralign> Figure 7. UART Group Settings </WRAP>
  
-The Logic Analyzer must be set up to “catch” the UART packet transfer on the Logic Analyzer plot. Therefore we need to configure a trigger. Since the UART transfer starts when the start bit is detected (transmission line is pulled from high to low), we need to trigger the falling edge of the transmission channel.+The Logic Analyzer must be set up to “catch” the UART byte transfer on the Logic Analyzer plot. Since the UART transfer starts with a start bit(transmit line is pulled from high to low), we can use this event to trigger the capture.
  
 <WRAP centeralign>{{:university:courses:electronics:uart_trigger_grp.png|}}</WRAP> <WRAP centeralign>{{:university:courses:electronics:uart_trigger_grp.png|}}</WRAP>
Line 127: Line 147:
 The Logic Analyzer will wait for the falling edge of the Rx signal to be triggered (corresponding to the start bit).  The Logic Analyzer will wait for the falling edge of the Rx signal to be triggered (corresponding to the start bit). 
  
-Run a single sweep on the Pattern Generator to send the first UART packet.+Run a single sweep on the Pattern Generator to send the first UART byte.
  
 The result captured by the Logic Analyzer is presented in Figure 10. The result captured by the Logic Analyzer is presented in Figure 10.
  
 <WRAP centeralign>{{:university:courses:electronics:uart_la_plot.png|}}</WRAP>  <WRAP centeralign>{{:university:courses:electronics:uart_la_plot.png|}}</WRAP> 
-<WRAP centeralign>Figure10. UART sequence plot </WRAP>+<WRAP centeralign>Figure 10. UART sequence plot </WRAP>
  
 Analyzing the plot, the byte (ASCII code) corresponding to character "A" is sent from the Pattern Generator and received at the EVAL-ADICUP3029 Rx pin. After the byte is received, on TX pin the byte is sent back and captured by the Logic Analyzer. Analyzing the plot, the byte (ASCII code) corresponding to character "A" is sent from the Pattern Generator and received at the EVAL-ADICUP3029 Rx pin. After the byte is received, on TX pin the byte is sent back and captured by the Logic Analyzer.
  
 +The decoders available in Scopy allow visualization of the data bytes in ASCII format, including the Start Bit (denoted with "S" on the plot) and the Stop bit (denoted with "T" on the plot).
 +
 +Now, let's try sending multiple characters and see what happens with our application.
 +
 +In the Pattern Generator instrument, under the "Data to Send" label, set the data bytes to "ADI".
 +
 +<WRAP centeralign>{{:university:courses:electronics:uart_data_to_send.png?400|}}</WRAP>
 +<WRAP centeralign>Figure 11. Pattern Generator - Data to send</WRAP>
 +
 +On the Logic Analyzer, adjust the Time Base and Trigger Position accordingly to be able to see all of the transactions. (i.e. Time Base: 100us and Trigger Position: 300us)
 +
 +Run Single sweep in The Logic Analyzer and then in the Pattern Generator.
 +
 +The result captured by the Logic Analyzer is shown in Figure 12.
 +
 +<WRAP centeralign>{{:university:courses:electronics:uart_la_plot2.png|}}</WRAP>
 +<WRAP centeralign>Figure 11. Pattern Generator - Data to send</WRAP>
 +
 +The EVAL-ADICUP3029 example program echoes received data bytes as they come in.  As expected all the data bytes were received by the EVAL-ADICUP3029 board and sent back on Tx pin.
 +
 +=====Conclusion=====
 +
 +In addition to UART, the application includes a set of decoders covering a large number of communication protocols such as I2C, I2S, SPI, JTAG, and others, making ADALM2000 a powerful tool for analyzing and debugging digital signals. 
 +
 +====Further Reading:====
 +  * [[adi>media/en/technical-documentation/application-notes/an-1435.pdf|Implementing UART Using the ADuCM3027/ADuCM3029 Serial Ports ]]
 +  * [[adi>media/en/technical-documentation/application-notes/EE-391.pdf|Implementing UART Using ADuCM302x Serial Ports]]
 +  * [[resources:eval:user-guides:eval-adpaq3029:resources:app_uart|EVAL-ADPAQ3029 - UART(Arduino) demo]]
 +  * [[resources:eval:user-guides:eval-adicup3029|EVAL-ADICUP3029 User Guide]]
 +  * [[university:tools:m2k|ADALM2000 Overview]]
 +  * [[university:tools:m2k:scopy|Scopy]]
  
university/courses/electronics/m2k-uart-debug.1553615417.txt.gz · Last modified: 26 Mar 2019 16:50 by Antoniu Miclaus