Electronic Design

Add Self-Detection To Serial Devices

Perhaps one of the most popular methods for communications between a personal computer and an external device is serial asynchronous communication, based on the RS-232 standard. The external device may be: development tools, debugging tools, measurement equipment, data acquisition, etc.,which are only occasionally connected to the PC. That’s because other more frequently used resources, such as a mouse, an external modem, or a trackball, need access to the limited number of serial ports. When it’s time to connect one of these lower-priority devices, confusion often arises over which COM port the device should be configured for.

Presented here is an interesting solution to consider for new designs. It involves a little extra hardware attached to the serial device, and a little extra software attached to the application on the PC.

The idea is to generate a ringing signal that can be detected by the PC application. In this way, the application can automatically detect the COM port at which the external device appears on.

The typical communication between a PC and a serial sevice uses only three wires: Rx, Tx, and ground. The MAX232 chip has four level translators. Only two are used to perform the link described—one for the received data (RS-232 to TTL translator) and one for the transmitted data (TTL to RS-232 translator). This leaves two available translators.

The RS-232 to TTL-level translator employed in the circuit has a special feature—a hysteresis of approximately 0.5 V. With this feature, a classical gate oscillator can be created (Fig. 1a). This oscillator may be built using the spare translators in the MAX232 (Fig. 1b). As shown in Figure 2, the oscillator output (with its RS-232 level) is connected to pin 9 of a DB-9 connector (or pin 22 of a DB-25 connector). This pin performs the Ring Indicator (RI) signal function on the RS-232 interface.

Now we have to create the software (see the listing) to be added to the PC application. The function to be performed needs to detect if the oscillation is present on the RING input of serial port that’s polled.

To do this, it begins polling each serial port controller (8250-based or 16x50-based UART), checking whether the oscillation described is present by reading the RING INDICATOR bit in the Modem Status Register (MSR). When this oscillation is detected, the device has been identified and is ready!

The SearchOscillator() function counts the number of times in a second that an edge on input signal RI is produced by checking bit 2 in MSR. This bit (called “TERI,” or Tailing Edge of Ring Indicator) indicates that the RI input has changed from low to high. This count is saved into the ringCount variable, and must be equal to the oscillator frequency.

A frequency detection band (“F_MAX, F_MIN”) is created to perform the oscillation detection more effectively. The time interval for this edge counting is indicated using the searchTimeOut global flag variable. It’s set to TRUE in the timer interrupt service routine, when the desired time (one second approximately) has passed. This function also is useful for verifying whether the serial device is powered or not. The DetectSerialDevice() function is used to poll for the possible serial ports mapped into the PC. It returns the I/O base address of the device that has been detected via the oscillator frequency signature.

The approach presented has been used successfully in several designs. It’s had success because it’s easy to implement, has no cost penalties, and eliminates user confusion and errors when configuring serial devices to the PC’s COM ports.

Protocols of higher level could be used (using Rx and Tx lines), when the serial device is identified, creating a simulated “Plug & Play” system.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.