Connecting a remote COM controller to the USB port of a computer via inconsistent lines
Until now, there are many devices that connect to the computer via the COM port, but since COM computers are increasingly rarely included in COM computers, communication with COM devices is via USB ports supplemented by special signal converters. A significant increase in the frequency of signals in the USB line (in comparison with the signals of the COM port) imposes a limit on the length of the lines, increases their cost and requires solving the issues of matching the lines. In this work, using the example of the Arduino UNO controller, we consider connecting a COM device to a computer through long, inconsistent lines.
A typical diagram of connecting the Arduino UNO controller to a computer via a USB port is shown in Figure 1. On the computer side, the communication channel is visible as a standard COM port. But, in fact, this is a virtual COM port with which the computer exchanges data packets at a frequency of 12 MHz, and a specialized controller located on the Arduino UNO board converts USB data packets into a sequence of bits in the format of an asynchronous UART interface with 0 / 5V levels, which and are used by the main Arduino UNO controller (ATmega328P chip) to download programs and exchange data with a computer during program execution.
Figure 1. Typical connection of an Arduino UNO controller to a computer via a USB port.
The timing diagram of serial data transmission according to the UART rules of the device with a signal level of 0 / 5V is shown in Figure 2. Data is transmitted in bytes. In addition to the data, the sequence contains start and stop bits and may include other service bits, for example, the parity bit, the application of which is specified in the COM port settings, one of the standard transmission rates is also set there.
Note. In the UART asynchronous interface family, the most well-known standard is the physical layer RS-232, used by the computer's COM port.
The COM port has no synchronization signals, time intervals are formed by both the transmitter and the receiver with a clock accuracy of no worse than 5%.
Figure 2. Timing diagram of the UART serial data transmission (01001011) of the ATmega328P chip of the Arduino UNO controller.
The Arduino UNO controller contains a specialized controller for converting UART signals to a USB sequence and vice versa. The computer’s USB port communicating with the virtual COM port works in Full-speed mode at a frequency of 12 Mbps (Figure 3). This mode supports as USB 1.0. so is USB 2.0.
Figure 3. Measured 4V signal on the differential USB – COM line of the Arduino controller. USB cable length 2m. The frequency of the signals on the USB line is 12 MHz. To generate the signals, data recording in the COM port of the controller was used. The frequency of USB data 12 MHz did not change when writing to the COM port at a speed of 9600 bps and 115200 bps.
Data on the USB bus is transmitted in packets (Figure 4). Packet sizes depend on the type of transmission being performed. Each packet in Full-speed mode contains 8 bits of clock synchronization of the receiver and transmitter (Sync), 8 bits of the packet identifier (PID) and 2 bits of the packet end (EOP). The data block can be from 0 to 1023 bytes.
Figure 4. An example of packet transmission via a differential USB 1.1 line in Full-speed mode [2]. The change in the state of the differential signal corresponds to the transfer of zero, the preservation of levels corresponds to the transfer of one. To improve synchronization on unit sequences, a zero is forced for every 6 units in a row.
In addition to the data packet, other packets are also transmitted. All USB transmissions require that 2 or 3 packets of information be transferred between the host controller and receiver. If the transfer is successful, the destination returns an acknowledgment packet. If an error is detected during transmission, a non-notification packet is generated.
Differential USB signals are transmitted over a twisted pair cable of a shielded 4-wire cable. According to the standard, the signal conductor cross-section of the high-speed USB 2.0 cable must be 28 AWG and from 20 to 28 AWG for power cores, depending on the cable length (see Table 1).
Table 1. Approximate correspondence between the length and diameter of the wires of the USB2 cable.
Wire size [3]
To increase the length of the USB cable, it is equipped with built-in signal amplifiers.
According to the requirements of the USB 2.0 specification for High-speed mode (up to 480 Mbps), the signal propagation delay in the cable should not exceed 5.2 ns / m and not more than 26 ns, which determines the maximum cable length of 5 m.
Delay per meter the length in the coaxial cable is inversely proportional to the wave propagation velocity in m / s, which is calculated as
,
where c is the speed of light 3 * 10 ^ 8 m / s; e is the dielectric constant of the material of the internal insulator; u is the magnetic permeability of the insulator. For polyethylene with u = 1 and e = 2.2, the phase velocity is 2 * 10 ^ 8 m / s and, accordingly, the delay is 5 ns / m.
To reduce signal loss, it is important to ensure uniformity of wave impedance ( v.s.) signal line. Change in W.S. may be due to poor-quality cable termination, poor matching of line elements, poor quality of the connector, etc.
The wave impedance of the cable is determined by its design. V.S. coaxial cable in the high frequency region (30 kHz and above) is calculated by the following formula.
where L is the longitudinal inductance of the shorted cable, GN; C is the transverse capacity of the open cable, f; e is the dielectric constant of the insulator; D is the diameter of the insulator; d is the diameter of the conductor. The value of V.S. independent of cable length.
The dielectric constant of insulators lies in the range 1 ... 7: 1 - air, vacuum; 1.3 ... 2.4 - polyethylene; 2.5..6 - rubber; 5..7 - porcelain; 6..7 - mica; 7 - glass.
The value of V.S. twisted pair USB 2.0 cable is 90 ± 15% Ohm [5]. Calculation VS shielded twisted pair must take into account the relative position of the conductors.
In a matched cable, which has a load at the ends, has a resistance equal to the V.S., all transmitted electromagnetic energy is completely absorbed by the receiver without reflection. In inhomogeneous lines and with inconsistent loads in places of electrical inconsistency, reflected waves arise and part of the energy returns to the beginning of the line.
The reflection coefficient of the waves in the cable is equal to the ratio
,
where rH is the load resistance; Z - V.S. cable.
The inclusion of mismatched elements in the USB line can significantly distort the signal. For example, the line appears to be inoperative when the inclusion of electric leads from the power cable with a wave impedance of 10 ... 40 Ohms.
To ensure stable communication between the remote COM device and the computer via the USB port, the length of the USB channel is minimized, a USB - RS-232 converter is installed at the output of the USB line, which is connected via a long line to the level converter + 15 / -15V == 0 / 5V, located near the Arduino controller and connected to its UART port, as shown in Figure 5. The data exchange rate in this structure is the same as when connecting the Arduino to a computer via a USB cable, but the signal frequency in the long line is almost 100 times lower - like 0 , 115200 Mbit / s and 12 Mbit / s.
Figure 5. Arduino UNO controller connection diagram to a computer via USB port and long inconsistent lines. The designation of the GND, Tx transmitter, and Rx receiver pins on the standard DB-9 connector on the computer's COM port is shown at the top left. On the device side, the TxD and RxD signals on the DB-9 connector must be swapped.
The RS232 level converter (Figure 5) does not change the sequence of bits. It changes the signal levels from 0/5 V to + 12 / -12 V and vice versa (Figure 6).
Figure 6. Timing diagram and signal levels of the RS232 converter.
Chips can be used to convert RS232 signal levels, for example, MAX232 (Maxim Integrated Products), SP232 (Sipex), ADM232 (Analog Devices). These microcircuits have the same characteristics and pin assignments. The connection of the MAX232 is shown in Figure 7 [6].
Figure 7. Connection diagram of the MAX232 level converter. The circuit provides an output voltage level of approximately ± 7.5 V corresponding to the RS-232 interface.
The market offers many modules of level converters built on the basis of these and other microcircuits. The appearance of one of these modules is shown in (Figure 5).
You can connect the device to a computer via a standard COM port, if any, or use a USB-RS232 converter (other names: USB-COM converters, adapters or adapters) connected to a USB port directly or through its own USB cable. The appearance of the USB converters is shown in Figure 5.
An embodiment of the layout of the COM device line — a USB port of a computer without an RS-232 line is shown in Figure 8.
Figure 8. Connection of the Arduino UNO controller to the USB-COM converter of the computer.
To check the operability of the data exchange channel between the Arduino UNO controller and the computer, a wire as shown in Figure 9 and Figure 10 was assembled through a long inconsistent line. Pieces of wire were connected by twisting or held in the socket jacks by friction.
Figure 9. RS232 channel from a 9.5 m composite cable.
Figure 10. RS232 channel pieces from a 9.5 m composite cable.
Data transmission and reception through the COM port of the Arduino UNO controller was controlled by the computer utility COM Port Toolkit.
The Arduino UNO program used to test the line, transmitting data bytes to the COM port and switching the controller LED upon the arrival of external commands, is shown below.
The waveforms of the signals taken at the ends of the pieces of RS-232 line are shown in Figure 11. Data is transmitted at a frequency of 115200 bps.
Figure 11. A signal with an amplitude of + 7.5 / -8 V at the ends of the RS-232 line of a composite cable 9.5 m long. The data transfer frequency is 115200 bit / s. The signal has no noticeable distortion.
Downloading programs to the Arduino controller is performed using its internal bootloader, which starts immediately after turning on the controller’s power, or after pressing the reset button on the board, or when the computer issues a reset signal via the USB line.
When the Arduino board was connected via the RS-232 channel with two signal lines Tx and Rx, in the absence of a reset signal line, the download was performed in the following order.
1. The Arduino development environment was launched (as in boot mode via USB).
2. The program was loaded (as in the boot mode via USB).
3. The firmware of the program was launched by the command Ctrl + U or via the button (as in the boot mode via USB)
4. Additionally, after starting the firmware and filling in the progress indicatorthe Reset button on the Arduino controller board was pressed for about 0.5 seconds.
Successful firmware ends with a message
.
The firmware was carried out successfully and with a short-term power off of the controller, instead of pressing the Reset button.
The Arduino controller bootloader can also be launched automatically from the computer, without pressing the Reset button or briefly turning off the power. For this, it is necessary, for example, to supplement the RS-232 channel with Tx, Rx, and GND with the RTS line and connect it via the level converter to the RESET input of the Arduino controller.
1. WikipediA. The Free Encyclopedia.
2. WikipediA. The Free Encyclopedia.
3. WikipediA. The Free Encyclopedia.
4. Transmission methods over twisted pairs.
5. USB2.0 A plug B plug multimedia cable.
6. + 5V-Powered, Multichannel RS-232 Drivers / Receivers.
7. Dr. Bob Davidov. Serial data port interface converter.
8. Dr. Bob Davidov.
USB Channel Structure - Arduino UNO Board
A typical diagram of connecting the Arduino UNO controller to a computer via a USB port is shown in Figure 1. On the computer side, the communication channel is visible as a standard COM port. But, in fact, this is a virtual COM port with which the computer exchanges data packets at a frequency of 12 MHz, and a specialized controller located on the Arduino UNO board converts USB data packets into a sequence of bits in the format of an asynchronous UART interface with 0 / 5V levels, which and are used by the main Arduino UNO controller (ATmega328P chip) to download programs and exchange data with a computer during program execution.
Figure 1. Typical connection of an Arduino UNO controller to a computer via a USB port.
The timing diagram of serial data transmission according to the UART rules of the device with a signal level of 0 / 5V is shown in Figure 2. Data is transmitted in bytes. In addition to the data, the sequence contains start and stop bits and may include other service bits, for example, the parity bit, the application of which is specified in the COM port settings, one of the standard transmission rates is also set there.
Note. In the UART asynchronous interface family, the most well-known standard is the physical layer RS-232, used by the computer's COM port.
The COM port has no synchronization signals, time intervals are formed by both the transmitter and the receiver with a clock accuracy of no worse than 5%.
Figure 2. Timing diagram of the UART serial data transmission (01001011) of the ATmega328P chip of the Arduino UNO controller.
The Arduino UNO controller contains a specialized controller for converting UART signals to a USB sequence and vice versa. The computer’s USB port communicating with the virtual COM port works in Full-speed mode at a frequency of 12 Mbps (Figure 3). This mode supports as USB 1.0. so is USB 2.0.
Figure 3. Measured 4V signal on the differential USB – COM line of the Arduino controller. USB cable length 2m. The frequency of the signals on the USB line is 12 MHz. To generate the signals, data recording in the COM port of the controller was used. The frequency of USB data 12 MHz did not change when writing to the COM port at a speed of 9600 bps and 115200 bps.
Data on the USB bus is transmitted in packets (Figure 4). Packet sizes depend on the type of transmission being performed. Each packet in Full-speed mode contains 8 bits of clock synchronization of the receiver and transmitter (Sync), 8 bits of the packet identifier (PID) and 2 bits of the packet end (EOP). The data block can be from 0 to 1023 bytes.
Figure 4. An example of packet transmission via a differential USB 1.1 line in Full-speed mode [2]. The change in the state of the differential signal corresponds to the transfer of zero, the preservation of levels corresponds to the transfer of one. To improve synchronization on unit sequences, a zero is forced for every 6 units in a row.
In addition to the data packet, other packets are also transmitted. All USB transmissions require that 2 or 3 packets of information be transferred between the host controller and receiver. If the transfer is successful, the destination returns an acknowledgment packet. If an error is detected during transmission, a non-notification packet is generated.
Differential USB signals are transmitted over a twisted pair cable of a shielded 4-wire cable. According to the standard, the signal conductor cross-section of the high-speed USB 2.0 cable must be 28 AWG and from 20 to 28 AWG for power cores, depending on the cable length (see Table 1).
Table 1. Approximate correspondence between the length and diameter of the wires of the USB2 cable.
Wire size [3]
To increase the length of the USB cable, it is equipped with built-in signal amplifiers.
According to the requirements of the USB 2.0 specification for High-speed mode (up to 480 Mbps), the signal propagation delay in the cable should not exceed 5.2 ns / m and not more than 26 ns, which determines the maximum cable length of 5 m.
Delay per meter the length in the coaxial cable is inversely proportional to the wave propagation velocity in m / s, which is calculated as
,
where c is the speed of light 3 * 10 ^ 8 m / s; e is the dielectric constant of the material of the internal insulator; u is the magnetic permeability of the insulator. For polyethylene with u = 1 and e = 2.2, the phase velocity is 2 * 10 ^ 8 m / s and, accordingly, the delay is 5 ns / m.
To reduce signal loss, it is important to ensure uniformity of wave impedance ( v.s.) signal line. Change in W.S. may be due to poor-quality cable termination, poor matching of line elements, poor quality of the connector, etc.
The wave impedance of the cable is determined by its design. V.S. coaxial cable in the high frequency region (30 kHz and above) is calculated by the following formula.
where L is the longitudinal inductance of the shorted cable, GN; C is the transverse capacity of the open cable, f; e is the dielectric constant of the insulator; D is the diameter of the insulator; d is the diameter of the conductor. The value of V.S. independent of cable length.
The dielectric constant of insulators lies in the range 1 ... 7: 1 - air, vacuum; 1.3 ... 2.4 - polyethylene; 2.5..6 - rubber; 5..7 - porcelain; 6..7 - mica; 7 - glass.
The value of V.S. twisted pair USB 2.0 cable is 90 ± 15% Ohm [5]. Calculation VS shielded twisted pair must take into account the relative position of the conductors.
In a matched cable, which has a load at the ends, has a resistance equal to the V.S., all transmitted electromagnetic energy is completely absorbed by the receiver without reflection. In inhomogeneous lines and with inconsistent loads in places of electrical inconsistency, reflected waves arise and part of the energy returns to the beginning of the line.
The reflection coefficient of the waves in the cable is equal to the ratio
,
where rH is the load resistance; Z - V.S. cable.
The inclusion of mismatched elements in the USB line can significantly distort the signal. For example, the line appears to be inoperative when the inclusion of electric leads from the power cable with a wave impedance of 10 ... 40 Ohms.
USB Channel Structure - RS-232 - Arduino UNO Board
To ensure stable communication between the remote COM device and the computer via the USB port, the length of the USB channel is minimized, a USB - RS-232 converter is installed at the output of the USB line, which is connected via a long line to the level converter + 15 / -15V == 0 / 5V, located near the Arduino controller and connected to its UART port, as shown in Figure 5. The data exchange rate in this structure is the same as when connecting the Arduino to a computer via a USB cable, but the signal frequency in the long line is almost 100 times lower - like 0 , 115200 Mbit / s and 12 Mbit / s.
Figure 5. Arduino UNO controller connection diagram to a computer via USB port and long inconsistent lines. The designation of the GND, Tx transmitter, and Rx receiver pins on the standard DB-9 connector on the computer's COM port is shown at the top left. On the device side, the TxD and RxD signals on the DB-9 connector must be swapped.
The RS-232 interface has the following characteristics [7,8].
Signal transmission method Single-phase
Maximum number of receivers 1
Maximum transmission speed 460 kbit / s
Maximum cable length 15 m (for 460 kbit / s) In-
phase output voltage ± 25
V Load impedance 3 ..7 k Ohm
Permissible signal range at the receiver input ± 25
V Receiver sensitivity ± 3V
Receiver input impedance 3 ..7 kOhm
Load capacity not more than 2500 pcF *
______________________
* When using a cable with a small capacity, communication can be maintained at distances up to 300 m [1].
The RS232 level converter (Figure 5) does not change the sequence of bits. It changes the signal levels from 0/5 V to + 12 / -12 V and vice versa (Figure 6).
Figure 6. Timing diagram and signal levels of the RS232 converter.
Chips can be used to convert RS232 signal levels, for example, MAX232 (Maxim Integrated Products), SP232 (Sipex), ADM232 (Analog Devices). These microcircuits have the same characteristics and pin assignments. The connection of the MAX232 is shown in Figure 7 [6].
Figure 7. Connection diagram of the MAX232 level converter. The circuit provides an output voltage level of approximately ± 7.5 V corresponding to the RS-232 interface.
The market offers many modules of level converters built on the basis of these and other microcircuits. The appearance of one of these modules is shown in (Figure 5).
You can connect the device to a computer via a standard COM port, if any, or use a USB-RS232 converter (other names: USB-COM converters, adapters or adapters) connected to a USB port directly or through its own USB cable. The appearance of the USB converters is shown in Figure 5.
An embodiment of the layout of the COM device line — a USB port of a computer without an RS-232 line is shown in Figure 8.
Figure 8. Connection of the Arduino UNO controller to the USB-COM converter of the computer.
To check the operability of the data exchange channel between the Arduino UNO controller and the computer, a wire as shown in Figure 9 and Figure 10 was assembled through a long inconsistent line. Pieces of wire were connected by twisting or held in the socket jacks by friction.
Figure 9. RS232 channel from a 9.5 m composite cable.
Figure 10. RS232 channel pieces from a 9.5 m composite cable.
Data transmission and reception through the COM port of the Arduino UNO controller was controlled by the computer utility COM Port Toolkit.
The Arduino UNO program used to test the line, transmitting data bytes to the COM port and switching the controller LED upon the arrival of external commands, is shown below.
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200); // запуск последовательного порта, 9600,115200
}
void loop()
{
if (Serial.available() >0) {
mode = Serial.read(); // read byte
switch (mode) {
case 1:
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
break;
case 2:
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
break;
}
}
Serial.print(5); // 6 or 9
}
The waveforms of the signals taken at the ends of the pieces of RS-232 line are shown in Figure 11. Data is transmitted at a frequency of 115200 bps.
Figure 11. A signal with an amplitude of + 7.5 / -8 V at the ends of the RS-232 line of a composite cable 9.5 m long. The data transfer frequency is 115200 bit / s. The signal has no noticeable distortion.
Arduino UNO controller firmware
Downloading programs to the Arduino controller is performed using its internal bootloader, which starts immediately after turning on the controller’s power, or after pressing the reset button on the board, or when the computer issues a reset signal via the USB line.
When the Arduino board was connected via the RS-232 channel with two signal lines Tx and Rx, in the absence of a reset signal line, the download was performed in the following order.
1. The Arduino development environment was launched (as in boot mode via USB).
2. The program was loaded (as in the boot mode via USB).
3. The firmware of the program was launched by the command Ctrl + U or via the button (as in the boot mode via USB)
4. Additionally, after starting the firmware and filling in the progress indicatorthe Reset button on the Arduino controller board was pressed for about 0.5 seconds.
Successful firmware ends with a message
.
The firmware was carried out successfully and with a short-term power off of the controller, instead of pressing the Reset button.
The Arduino controller bootloader can also be launched automatically from the computer, without pressing the Reset button or briefly turning off the power. For this, it is necessary, for example, to supplement the RS-232 channel with Tx, Rx, and GND with the RTS line and connect it via the level converter to the RESET input of the Arduino controller.
Conclusion
- SOM data transmission via an extended USB line is carried out by packets at higher frequencies (12 MHz) and requires a coordinated line.
- Minimizing the length of the USB path and using a long line to send COM data directly made it possible to ensure reliable data transfer through pieces of uncoordinated wires with a total length of 9.5 m.
- RS-232 data can be transmitted at low frequencies over lines with low capacitance (less than 2500 pF) can be carried out at distances up to 300 m.
- The use of RS-422 or 485 differential lines for remote communications with a computer USB port allows increasing the distance up to 1200 m, but when solving the issue of line matching.
Literature
1. WikipediA. The Free Encyclopedia.
2. WikipediA. The Free Encyclopedia.
3. WikipediA. The Free Encyclopedia.
4. Transmission methods over twisted pairs.
5. USB2.0 A plug B plug multimedia cable.
6. + 5V-Powered, Multichannel RS-232 Drivers / Receivers.
7. Dr. Bob Davidov. Serial data port interface converter.
8. Dr. Bob Davidov.