This is an old revision of the document!
Unit 4 Part 2: Communications - Asynchronous Serial Protocols
Unit 4 Part 2 Labs
Download This Document
1. Introduction
Asynchronous communication is the transmission of data between two devices that are not synchronized with one another via a clocking mechanism or other technique. Data is exchanged in blocks of a fixed number of bits that are bracketed by a START and STOP bit. The term asynchronous implies the sender can initiate data transmission at any time, and the receiver must be ready to accept information when it arrives. The two devices must be operating at or nearly equal to the same frequency.
2. Objectives:
- Program the PIC32MX370 to use the Universal Asynchronous Receiver Transmitter (UART) serial communications to display data on a computer using a terminal emulation program.
- Control the stepper motor speed and direction of rotation using commands entered from a terminal emulation program.
- Display serial communications on the LCD and PC terminal.
3. Basic Knowledge:
- How to map PIC32MX370 I/O pins to special function registers.
- How to initialize special functions using the PLIB functions.
4. Unit Equipment List
4.1. Hardware
- Workstation computer running Windows 10 or higher, MAC OS, or Linux
- 4-wire stepper motor (Lab 4b only)
- 5V, 2.5A DC power supply (Lab 4b only)
In addition, we suggest the following instruments:
4.2. Software
The following programs must be installed on your development work station:
5. Project Takeaways
- Understanding of the basics of telecommunications.
- Understanding of requirements and implementations of asynchronous communications.
- Application of asynchronous communications
- Knowledge of a PC terminal emulation program.
- How to develop a library of PIC32 software to provide bi-directional communications of single characters and strings of characters.
- How to use the UART for diagnostics and as a human-machine interface (HMI).
- How to recognize the handshaking methods used in a communications protocol.
- How to setup the Analog Discovery 2 to display UART waveforms.
6. Fundamental Concepts
6.1. Asynchronous Communications
Serial communications is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication where several bits are sent as a whole on a link with several parallel channels. Both parallel and serial communications have handshaking requirements to synchronize data transfers. Although parallel communications generally has a speed advantage over serial communications, the primary advantage for serial communications is the reduced number of processor I/O pins and connecting wires or conductors.
Although some references claim that asynchronous communications take place outside of real-time, this does not mean that timing is not critical to the transmission of data. Each data symbol is uniform in period and has critical timing requirements. In digital communications, symbol rate (also known as baud or modulation rate) is the number of symbol changes (waveform changes or signaling events) made to the transmission medium per second using a digitally modulated signal or a line code. The symbol rate is measured in baud or symbols/second. Each symbol can represent or convey one or several bits of data. The symbol rate is related to, but should not be confused with, the gross bit rate expressed in bits/second. (See Symbol Rate.)
A user unfamiliar with asynchronous communications and UART operations should refer to Reference 3 in section 8 of this document. Asynchronous communications is a serial data protocol that has been in use for many years. Normally, eight bits of data are transmitted at a time. There are other less commonly used modes that can send 5, 6, or 7 bits of data. Each byte of data is framed by a start bit and a stop bit. A symbol is defined as a start, data, parity, or stop bit. It is common to define communications speed as bits per second. The bit rate is defined as the inverse of the period of a unit symbol. Although the common standard bit rates are 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, and 115200, communications is possible at any rate provided that the sender and receiver use the same rate. For most asynchronous communications, the term “baud” is commonly used interchangeably with the term “bit rate.”
Figure 6.1 shows a typical asynchronous transmission of two 8-bit data bytes. We see that the idle state of the transmit signal is a logic one, or a high voltage level. A START bit is signified by a high to low transition and remains low for one symbol time. The START bit is followed by eight data bits with the least significant bit being sent first. A logic zero is sent when the signal is a low voltage level for one symbol time. Similarly, a logic one is sent when the signal is a high voltage level for one symbol time. After the transmitting of the data there may be an optional parity bit. The parity bit is used for error detection and can be set for even parity or odd parity. For even parity, the parity bit is set high if the number of ones in the preceding eight data bits are odd, thus making the total number of 1’s in the data plus parity bit even. Conversely, for odd parity, the parity bit is set high if the number of ones in the 8 data is even. The data byte is terminated with one or more successive stop bits. Stop bits are always a logic 1 or high voltage level. If the signal remains high for longer than one symbol period, the stop bit can be thought of as the stop or idle period and the communications signal may remain in the idle condition an arbitrarily long period of time.
Figure 6.1. Example of 115 kB asynchronous serial data stream with odd parity.
The receiving device unit must use the same bit rate as the sending unit. In the process of receiving serial communications, a processor may generate up to three error flags. A parity error is generated if the parity bit is the incorrect voltage level. The second type of error is a framing error that is generated if a low voltage level is received in the stop bit position. Thirdly, an overrun error is generated if a software instruction does not read the data byte from the receive buffer before the next byte of data is completely received, resulting in the new data byte overwriting the previous data byte.
Each new start bit synchronizes the sampling of the receiving unit. Generally, the receiver recovers the transmission using a clock that is an even multiple of the bit rate. When the receiving unit detects the falling edge of the START bit, it waits one half the symbol period and samples the receive data line. This is illustrated by the processor sample points in Fig. 6.1. If the logic state of the line is zero, then it is recognized as a valid start condition. The receiver then waits full periods to sample the receive data line until all data bits, plus any parity bit, plus the stop bit have been received. If a stop bit is not received, a framing error is generated.
Just like with parallel communications, there are three modes of serial communications: full-duplex, half-duplex, and simplex. Full-duplex describes the operation when a device can simultaneously send and receive data. Half-duplex operation allows both sending and receiving, but not simultaneously. Simplex operations are where the device can only send or receive data.
The actual data rate is defined as the number of data bits per unit time. Data efficiency is defined as the number of data bits divided by the total number of bits. The efficiency of asynchronous serial communications is at best 80% because there are always two extra data bits (start and stop bit) sent for each 8 data bits. If parity is used, the efficiency drops to 73% because 11 bits are needed to communicate 8 bits of data.
6.2. UART and FTDI-232
The PIC32 processors, as do most microprocessors, have a UART hardware embedded inside. “A universal asynchronous receiver/transmitter, abbreviated UART /ˈjuːɑːrt/, is a computer hardware device that translates data between characters (usually bytes) in a computer and an asynchronous serial communication format that encapsulates those characters between start bits and stop bits. UARTs are commonly used in conjunction with communication standards such as TIA (formerly EIA) RS-232, RS-422 or RS-485. The universal designation indicates that the data format and transmission speeds are configurable. The electric signaling levels and methods (such as differential signaling, etc.) are handled by a driver circuit external to the UART.”1) (Refer to Appendix C for commonly used definitions.)
6.3. UART Hardware
The Basys MX3 processor board uses an FTDI USB to serial adaptor that interfaces directly with the PIC32MX370 UART pins, as shown in Fig. A.1, with the physical location of the UART USB connector shown in Fig. A.2. The UART_RX and UART_TX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. The result of this wiring will be discussed below in the UART Software section. When the USB cable is connected to both the PC and J10 of the Basys MX3 processor board, the PC software will automatically enumerate the connection to a COMM port. To determine which COMM port is enumerated, you will need to click on the Windows Start icon in the lower left corner followed by clicking on “Device Manager” and then on “Ports (COM & LPT).” You will then see a listing as “USB Serial Port (COM##)” where “##” is the COMM number used when you open the terminal emulation application.
6.4. UART Software
As stated above, the UART_TX and UART_RX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. Table 6.1 shows that port F, pin 13 is mapped to U4RX using the C program statement “U4RXR = 0x09;”. Similarly, Table 6.2 shows that port F, pin 12 is mapped to U4TX using the C program statement “RPF12R = 0x02;”. After the PPS pin mapping shown in Listing B.1, all serial communications will use UART 4. The complete function to initialize UART 4 is shown in Listing B.1.
Table 6.1. PPS mapping of PIC32 port F pin 13 to UART 4 receive adapted from PIC32MX330/350/370/430/450/470 Family Data Sheet, Table 12-1.
| Peripheral Pin | [pin name]R SFR | [pin name]R bits | [pin names]R Value to RPn Pin Selection |
|---|---|---|---|
| INT1 | INT1R | INTR<3:0> | 0000 = RPD1 0001 = RPG9 0010 = RPB14 0011 = RPD0 0100 = RPD8 0101 = RPB6 0110 = RPD5 0111 = RPB2 1000 = RPF3(4) 1001 = RPF13(3) 1010 = Reserved 1011 = RPF2(1) 1100 = RPC2(3) 1101 = RPE8(3) 1110 = Reserved 1111 = Reserved |
| T3CK | T3CKR | T3CKR<3:0> | |
| IC1 | IC1R | IC1R<3:0> | |
| $\overline{(U3CTS)}$ | U3CTSR | U3CTSR<3:0> | |
| U4RX | U4RXR | U4RXR<3:0> | |
| U5RX | U5RXR | U5RXR<3:0> | |
| $\overline{(SS2)}$ | SS2R | SS2R<3:0> | |
| OCFA | OCFAR | OCFAR<3:0> |
**Table 6.2. PPS mapping of PIC32 port F pin 12 to UART 4 transmit adapted from PIC32MX330/350/370/430/450/470 Family Data Sheet, Table 12-2.
| RPn Port Pin | RPnR SFR | RPnR bits | RPnR Value to Peripheral Seleciton |
|---|---|---|---|
| RPD9 | RPD9R | RPD9R<3:0> | 0000 = No Connect 0001 = $\overline{(U3RTS)}$ 0010 = U4TX 0011 = REFCLKO 0100 = U5TX 0101 = Reserved 0110 = Reserved 0111 = $\overline{(SS1)}$ 1000 = SDO1 1001 = Reserved 1010 = Reserved 1011 = OC5 1100 = Reserved 1101 = C1OUT 1110 = Reserved 1111 = Reserved |
| RPG6 | RPG6R | RPG6R<3:0> | |
| RPB8 | RPB8R | RPB8R<3:0> | |
| RPB15 | RPB15R | RPB15R<3:0> | |
| RPD4 | RPD4R | RPD4R<3:0> | |
| RPB0 | RPB0R | RPB0R<3:0> | |
| RPE3 | RPE3R | RPE3R<3:0> | |
| RPB7 | RPB7R | RPB7R<3:0> | |
| RPB2 | RPB2R | RPB2R<3:0> | |
| RPF12(4) | RPF12R | RPF12R<3:0> | |
| RPD12(4) | RPD12R | RPD12R<3:0> | |
| RPF8(4) | RPF8R | RPF8R<3:0> | |
| RPC3(4) | RPC3R | RPC3R<3:0> | |
| RPE9(4) | RPE9R | RPE9R<3:0> |
- This selection is not available on 64-pin USB devices.
- This selection is only available on 100-pin General Purpose devices.
- This selection is not available on 64-pin General Purpose devices.
- This selection is not available when USBID functionality is used.
7. Background Information
The theory behind asynchronous and synchronous communication is essentially the same: Point B needs to know when a transmission from Point A begins, when it ends, and if it was processed correctly. However, the difference lies in how the transmission is broken down. Think of the difference in terms of a friendly chat. With asynchronous communication you would need to stop after every word to make sure the listener understood your meaning, and knew that you were about to speak the next word. With synchronous communication, you would establish with your listener that you were speaking English, that you will be speaking words at measured intervals, and that you would utter a complete sentence, or paragraph, or extended soliloquy, before pausing to confirm understanding. Further, you would establish with your listener beforehand that any extraneous noises you make during the speech or between speeches (coughing, burping, and hiccupping) should be ignored. Clearly the second approach is much faster, even though initializing communication may take slightly longer. In fact, by replacing the start, stop, and parity bits around individual words with start, stop, and control (processing instructions and error checking) sequences around large continuous data blocks, synchronous communication is about 30% faster than asynchronous communication, before any other factors are considered.
Synchronous vs. asynchronous communications pertain to the individual symbol or bit timing and is controlled at layer 1 in the OSI model. Synchronous serial communication describes a serial communication protocol in which “data is sent in a continuous stream at a constant rate.”2)
Synchronous communication requires that the clocks in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No start or stop bits are required. For this reason, “synchronous communication permits more information to be passed over a circuit per unit time” than asynchronous serial communication. Over time the transmitting and receiving clocks will tend to drift apart.
7.1. Asynchronous Digital Communications
In telecommunications, asynchronous communication is transmission of data, generally without the use of an external clock signal, where data can be transmitted intermittently rather than in a steady stream. Any timing required to recover data from the communication symbols is encoded within the symbols. One characteristic of asynchronous communications is that data is formed in units of transmission with well-defined size (number of bits) and symbol rate. Since over time the transmitting and receiving clocks will tend to drift apart resynchronization is required. The resynchronization is accomplished using a “START” symbol while the units of transmission are framed between a START and STOP symbol. The timing between units of transmission is arbitrary depending on the application requirements. Unit 4 Part 2 along with Lab 4a and Lab 4b explore asynchronous communication concepts and applications further.
7.2. Synchronous Digital Communications
Synchronous serial communication describes a serial communication protocol in which “data is sent in a continuous stream at a constant rate.” Synchronous communication requires that the clocks in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No START or STOP bits are required. The message framing is accomplished using a separate handshaking device select signal. The processor manages the data stream in units of transmission based on a pre-assigned number of bits. All PIC32 processors can be configured for 8, 16, or 32-bit transmission units. The net result is that synchronous communication permits more information to be passed over a circuit per unit time than asynchronous serial communication.
The synchronous communications circuit uses a separate clock signal or embeds the clock signal inside the data bit waveform. In either case, the clock implements handshaking and indicates when the receiving device should sample the input to determine the symbol value. As such, each symbol can have differing and arbitrary periods. As you will see in Lab 4d, the I2C protocol uses a 9-bit partition for each data byte (8 bits of information). The example explored in Lab 4c uses the SPI protocol, which segments the data stream into 8-bit data bytes.
8. References
- Embedded Computing and Mechatronics with the PIC32 Microcontroller, 1st Edition, by Kevin Lynch (Author), Nicholas Marchuk (Author), Matthew Elwin (Author), https://www.amazon.com/Embedded-Computing-Mechatronics-PIC32-Microcontroller/dp/0124201652
- “PIC32MX330/350/370/430/4450/470 32 Bit Microcontroller Datasheet (60001185E)”, http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf
- Serial Protocols Compared, http://www.embedded.com/design/connectivity/4023975/Serial-Protocols-Compared
- PIC32MX330/350/370/430/450/470 Family Data Sheet
Appendix A: Unit 4 Parts Configuration
Figure A.1. Unit 4 hardware and instrumentation configuration.
Appendix B: Partial List of Popular Serial Protocols
- LIN Local Interconnect Network
- SDLC/HDLC High Level Data Link Control (Traffic Control)
- ARINC 818 Avionics Digital Video Bus
- USB Universal Serial Bus (moderate-speed, for connecting peripherals to computers)
- FireWire IEEE 1394
- Ethernet IEEE 802.3
- Fiber Channel (high-speed, for connecting computers to mass storage devices)
- InfiniBand (very high speed, broadly comparable in scope to PCI)
- MIDI control of electronic musical instruments
- DMX512 control of theatrical lighting
- SDI-12 industrial sensor protocol
- SpaceWire Spacecraft communication network

