Menu English Ukrainian russian Home

Free technical library for hobbyists and professionals Free technical library


ENCYCLOPEDIA OF RADIO ELECTRONICS AND ELECTRICAL ENGINEERING
Free library / Schemes of radio-electronic and electrical devices

USB-COM-LPT converter on a microcontroller

Free technical library

Encyclopedia of radio electronics and electrical engineering / Computers

Comments on the article Comments on the article

The article describes a simple converter that allows you to connect peripheral devices equipped with an LPT interface to a computer that has only a USB interface. The conversion is carried out in two stages - a specialized microcircuit converts USB to COM (RS-232), and then the microcontroller converts COM to LPT. Since the computer in this case exchanges information through a virtual COM port, only programs developed or modified with this feature in mind will be able to interact through the proposed converter with an external LPT device. For everyone else, you will need to connect a special software driver to the operating system, which is yet to be developed.

At one time, many electronic devices and devices connected to the LPT port of a personal computer were developed and manufactured. They still exist today. At the same time, LPT ports (as well as COM ports, by the way) in computers are gradually replacing the USB interface. This process is especially fast in portable computers (notebook). But due to their compactness and autonomy, it is very convenient to use such computers as portable tools for setting up various electronic equipment, including those with an LPT interface. The elimination of LPT ports in computers makes working with such equipment problematic.

To solve this problem, a converter is proposed that uses inexpensive and affordable electronic components and has an open architecture for developing your own programs. The presence of a microcontroller in it allows, if necessary, to develop any necessary protocol for the exchange of information between a computer and a device connected through the converter.

The figure shows the converter circuit. The information transmitted through the X1 connector via the USB interface is converted using the CP2103-GM chip [1] into the RS-232 serial interface format. It also performs the reverse transformation. The outputs of the control lines of the RS-232 interface of this microcircuit are connected by jumpers corresponding to the constant readiness for information exchange. The TXD and RXD pins are connected respectively to the information input and output of the built-in UART microcontroller ATmega8515-8AC [2]. Connector X2 is intended for in-circuit programming of the microcontroller.

USB-COM-LPT converter on a microcontroller

Working according to the program, the boot codes of which are given in the table, the microcontroller processes the computer commands received at the input of the built-in UART. Performing them, it generates the output signals of the LPT port on its outputs and the contacts of the XXNUMX connector connected to them and receives the input signals of this port. The program is written in C language in the CodeVision development environment.

According to the information exchange protocol developed by the author and embedded in the microcontroller program, the computer must send two- or three-byte commands to the converter. The least significant bit of the first byte of the command specifies the direction of information transfer: O - from the computer to the converter (record); 1 - in the opposite direction (reading). The next bit defines the address space: 0 - LPT port register; 1 - non-volatile data memory of the microcontroller. The six most significant bits of the first byte are not used yet. The second byte of the command contains the address of a register or memory location, which can be in the range 0-255. The third byte is present only in write commands and contains a code intended to be entered into a register or memory cell. In response to a two-byte read command, the converter sends one byte to the computer - the contents of the requested register or memory cell. The initiator of the transfer of information in any direction is always a computer.

USB-COM-LPT converter on a microcontroller

The ability to read and write information from the EEPROM of the microcontroller, although not required for the application in question, is useful for the development and improvement of the functions performed by the converter. For example, in order to write byte 0x01F to the EEPROM of the microcontroller at address 0x5, the computer must send a sequence of three bytes through the virtual COM port: 0x03, 0x01, 0x5F. And to read data at the same address, a command of two bytes is enough: 0x02, 0x01. In response to it, the converter will send the byte read from the specified EEPROM cell.

As you know, from the point of view of the programmer, the LPT port in normal (not EPP or ECP) ​​mode of operation consists of three registers: data (DR), status (SR) and control (CR). The address of the DR register is the same as the base address of the port, the addresses of the SR and CR registers are larger by one and two units, respectively. This structure of the LPT port is also implemented in the proposed device. The assignment of bits of all registers is also completely preserved. This allows you to recycle previously created computer programs to work with the described converter at minimal cost.

The program includes header files describing the names of microcontroller registers and entries of binary values ​​of numbers used to initialize variables and other operations.

The program configures the UART of the microcontroller to work in asynchronous mode at a speed of 115200 baud with eight information (no parity) and one stop bit. The computer's virtual COM port must be configured in the same way. There are routines for receiving (UART_RXD) and transmitting bytes (UART_TXD) via UART, as well as routines for writing (WRLPT) and reading RD_LPT of LPT port registers and non-volatile memory cells (WR_EEPROM and RD_EEPROM).

For maximum compatibility with LPT, register masks MaskSR and MaskCR are provided. When information is output to the microcontroller port lines connected to the XXNUMX connector, or it is input from these lines, certain bits of the SR and CR registers are automatically inverted using the mentioned masks and the XOR logical operation (exclusive OR).

The source text of the program is provided with a detailed commentary, which allows you to understand it without much difficulty.

To ensure operation with the converter, it is necessary to install a software driver for the virtual COM port in the computer, which ensures the exchange of information with the CP2103 chip. This driver is freely available on the website of the manufacturer of these chips at silabs.com/public/documents/software_doc/drivers/Microcontrollers /lnterface/en/CP210x_VCP_Win2K_XP_S2K3.exe.

To check the converter, you can use a variety of test and debug programs that allow you to work with the COM port if they do not directly access the registers of this port, as was usually done in DOS and Windows9X/Me. Such calls should be replaced with port functions (eg, CreateFile, Get-CommConfig, SetCommConfig, Read-Corn, WriteFile) provided by the operating system.

After the converter is turned on, the HL3 LED lights up. Receiving the first byte of the command will extinguish it. After receiving the command in full and executing it, the LED will turn on again, which means that it is ready to receive the next command. Such an algorithm is convenient for monitoring the passage of commands and the normal operation of the converter.

In case the microcontroller freezes, the program uses a watchdog timer that will restart the microcontroller when such a situation occurs. This improves the stability of the inverter even when operating in a strong interference environment.

A complete set of microcontroller program project files can be downloaded here.

Literature

  1. СР2103 - Single-Chip USB to UART Bridge. - silabs.com:80/public/documents/tpub_doc/dsheet/Microcontrollers/Interface/en/cp2103.pdf
  2. ATmega8515, ATmega8515L - 8-bit Microcontroller with 8K Bytes In-System Programmable Flash. - atmel.com/dyn/resources/prod/documents/doc2512.pdf

Author: O.Valpa, Miass, Chelyabinsk Region; Publication: radioradar.net

See other articles Section Computers.

Read and write useful comments on this article.

<< Back

Latest news of science and technology, new electronics:

Artificial leather for touch emulation 15.04.2024

In a modern technology world where distance is becoming increasingly commonplace, maintaining connection and a sense of closeness is important. Recent developments in artificial skin by German scientists from Saarland University represent a new era in virtual interactions. German researchers from Saarland University have developed ultra-thin films that can transmit the sensation of touch over a distance. This cutting-edge technology provides new opportunities for virtual communication, especially for those who find themselves far from their loved ones. The ultra-thin films developed by the researchers, just 50 micrometers thick, can be integrated into textiles and worn like a second skin. These films act as sensors that recognize tactile signals from mom or dad, and as actuators that transmit these movements to the baby. Parents' touch to the fabric activates sensors that react to pressure and deform the ultra-thin film. This ... >>

Petgugu Global cat litter 15.04.2024

Taking care of pets can often be a challenge, especially when it comes to keeping your home clean. A new interesting solution from the Petgugu Global startup has been presented, which will make life easier for cat owners and help them keep their home perfectly clean and tidy. Startup Petgugu Global has unveiled a unique cat toilet that can automatically flush feces, keeping your home clean and fresh. This innovative device is equipped with various smart sensors that monitor your pet's toilet activity and activate to automatically clean after use. The device connects to the sewer system and ensures efficient waste removal without the need for intervention from the owner. Additionally, the toilet has a large flushable storage capacity, making it ideal for multi-cat households. The Petgugu cat litter bowl is designed for use with water-soluble litters and offers a range of additional ... >>

The attractiveness of caring men 14.04.2024

The stereotype that women prefer "bad boys" has long been widespread. However, recent research conducted by British scientists from Monash University offers a new perspective on this issue. They looked at how women responded to men's emotional responsibility and willingness to help others. The study's findings could change our understanding of what makes men attractive to women. A study conducted by scientists from Monash University leads to new findings about men's attractiveness to women. In the experiment, women were shown photographs of men with brief stories about their behavior in various situations, including their reaction to an encounter with a homeless person. Some of the men ignored the homeless man, while others helped him, such as buying him food. A study found that men who showed empathy and kindness were more attractive to women compared to men who showed empathy and kindness. ... >>

Random news from the Archive

3D in your pocket - so far only expensive offers 24.10.2011

Technologies, the introduction of which until recently seemed a matter of the distant future, have already been implemented. So, now you can buy a smartphone with a 3D screen that does not require special glasses. Sales of one of the most expensive communicators on the market, NTS EVO 3D, have started in Russia. Its average retail price of 24 rubles is justified by its equipment.

The device has a screen with a resolution of 960x540 pixels, allowing you to view stereo images without glasses. At the same time, the new NTS is able to shoot voluminous photos and videos by itself. True, our testing showed that the two cameras with a resolution of five megapixels are located too close to each other, which is why a good stereo effect appears only on objects shot in close proximity. At the same time, the device is very good for creating ordinary pictures.

The camera has autofocus and turns on by pressing a separate hardware button, switching between 2D and 30-modes is also assigned a separate lever. The "stuffing" of the smartphone corresponds to its price: a dual-core processor with a frequency of 1,2 GHz, internal memory of 1 GB and a large 43-inch screen.

Other interesting news:

▪ Marvell 88EM8189 LED driver IC

▪ The pendant will protect from criminals

▪ Biochemical Reboot of the Eye: Treating Blindness

▪ sounding wall

▪ Explosives will improve the safety of electric cars

News feed of science and technology, new electronics

 

Interesting materials of the Free Technical Library:

▪ section of the site for the radio amateur-designer. Article selection

▪ article Trumpet of Jericho. Popular expression

▪ article What is the upper temperature limit at which microorganisms can live? Detailed answer

▪ article Work on waxing machines. Standard instruction on labor protection

▪ article Power regulator on the chip KR1182PM1. Encyclopedia of radio electronics and electrical engineering

▪ article Millimeter waves in communication systems. Encyclopedia of radio electronics and electrical engineering

Leave your comment on this article:

Name:


Email (optional):


A comment:





All languages ​​of this page

Home page | Library | Articles | Website map | Site Reviews

www.diagram.com.ua

www.diagram.com.ua
2000-2024