Cogito ergo sum - Oliver's Playground

Cogito ergo sum


Advertising

Simulation of Serial Connections in AVR Studio 4

How to connect terminal programs via HAPSIM and com0com

By Oliver Müller


Helmut Wallner created with his HAPSIM a great simulator of peripheral devices for the AVR Simulator of Atmel's AVR Studio 4. Besides simulation of LCDs, LEDs, push buttons and keypads his software simulates terminal connections. A HAPSIM terminal can be connected to the simulated USARTs of the AVR microcontroller, running as simulation in AVR Studio 4. Wallner also provided support to redirect his simulated USART ports to real or virtual COM: ports of the Windows operating system. Wallner uses for this the Virtual Serial Port Kit, a proprietary product of Fabula Tech. With the open-source project com0com it is also possible to support virtual serial ports on Windows, but for free. This article shows how to use com0com together with HAPSIM to connect terminal programs to the AVR Simulator in AVR Studio 4.

Basic Setup

It is assumed that you have installed WinAVR, AVR Studio 4 and HAPSIM. First you have to extract Helmut Wallner's utrans sample to some directory. Edit the batch file build.bat and adjust the path of WinAVR at the line

set path=d:\winavr\utils\bin;d:\winavr\bin;%PATH%

to meet your WinAVR installation. Now build utrans by executing build.bat. You should see the file utrans.elf as result in the directory where you extraced the sample.

Selecting AVR Simulator and ATmega128 for utrans.
Fig. 1: Selecting AVR Simulator and ATmega128 for utrans.

Start AVR Studio 4 now and open the file utrans.elf. Select AVR Simulator and ATmega128 as shown in figure 1. After that start HAPSIM. It should detect the running AVR Studio automatically. In HAPSIM load the configuration utrans.xml by using the menu item File → Open configuration.

In AVR Studio press F5 to run the program. You should see output in the terminals which are connected to USART0 and USART1 of AVR Simulator as shown in figure 2. Whenever you type something in the terminal window entitled with USART0, the simulated ATmega128 will respond by sending this text as output to USART1 which will display in the corresponding terminal window in HAPSIM. If you type some text to the window entitled USART1 you will see the respond of the simulated ATmega128 in the USART0 window respectively.

The USART simulation of HAPSIM together with AVR Studio's AVR Simulator works already. Now it is time to redirect the input and output from the terminals in HAPSIM to virtual COM: ports and "real" terminal programs.

Terminals connected to simulated USARTs in HAPSIM.
Fig. 2: Terminals connected to simulated USARTs in HAPSIM.

Virtual Serial Ports with com0com

Download the most recent com0com package and start the setup.exe. Follow the instructions and accept the installation of the driver even if Windows cannot verify the vendor's certificate. The driver is signed but – as so often in the open-source field – not with a publicly trusted certificate.

Start the com0com setup program via the Programs menu of the Windows Start button. You will see one existing virtual port pair already. A virtual port pair is a virtual connection between two virtual COM: ports. At each COM: port of this pair you can connect an application. The applications will then communicate over these virtual ports as they were interconnected over physical serial ports. By com0com it is possible to connect one port of this pair to HAPSIM and the other to a terminal program, e. g. PuTTY or Hyperterminal. Et voilà you have connected your simulated AVR microcontroller to standard terminal software.

Because the utrans sample uses two terminals it is necessary to create an additional virutal port pair. To do so click the button Add Pair. After a short time you will see a second virtual port pair as in figure 3.

Virtual port pairs in com0com's setup program.
Fig. 3: Virtual port pairs in com0com's setup program.

Establishing the Connection

Restart HAPSIM and reopen utrans.xml. In HAPSIM click into the USART0 window and select the menu item Options → Terminal Settings. Check the option Redirection to and select CNCA0 as port. Click the button Settings and select the communication parameters for your terminal program. In our case you can leave the settings as they are (1200 8n1, no flow control). After setup of USART0 select USART1. Repeat the same steps but redirect it to CNCA1 (not CNCB0!!!).

Now it's time to connect the terminal programs to the other COM: ports of the pairs. We will demonstrate it by using PuTTY. Start a PuTTY session and select under Connection type the option serial. As in figure 4 enter into the field Serial line CNCB0 and into Speed 1200 (or the corresponding value of your setup in HAPSIM). Click the OK button and the serial terminal opens.

Start now another PuTTY session and select a serial connection again. In Serial line enter CNCB1 and into Speed the appropriate baud value. Click OK and the second serial terminal is ready to use.

Serial line setup in PuTTY.
Fig. 4: Serial line setup in PuTTY.

Restart utrans in AVR Studio again. To do so reset the AVR Simulator by pressing Shift+F5 and start anew by pressing F5 afterwards. Now you should see the output of utrans in PuTTY's terminal windows. While typing characters in one window the result appears in the other window.

This little demo with Helmut Wallner's utrans sample shows that is it possible to use com0com for redirecting HAPSIM's simulated terminals to "real" terminal programs without any costs.


Copyright © 2011 Oliver Müller. All rights reserved.
Published on http://www.cogito-ergo-sum.org, March 30th 2011.

If you like this article support the author's work with a little payment, please.


Natural Science & Mathematics

Languages

Computer Application

Electronic and Microcontrollers

Downloads

If you like the content of this site I would be happy if you were supporting it with an ex gratia payment.



Original Layout by Ruthsarian Layouts (see OSWD).