ATMega32 UART PC Interface – Testing

This article shows to test the ATMega32 UART PC Interface, and how to configure the software. Assuming you have made the interface, all that is required now is the software and the configuration. The hardware is simply a MAX232 chip, which provides the electrical translation between RS232 signal levels and TTL. The connection to the ATmega32 enables Windows HyperTerminal to display the data sent by the microcontroller.

ATMega32 UART PC Interface - Testing

Terminal emulators are one of those old technologies that have remained with us since the early days of the IBM computers. It always reminds me of that old classic film “War Games”, where David Lightman (Matthew Broderick) hacks into a military network using a terminal emulator program and a PSTN modem.

This is a simple example program that will print, “Hello…would you like to play a game?” in the HyperTerminal window.

UART.H and UART.C Support Files

In order to print to Windows HyperTerminal, you will need two support files, which will provide serial communications between the PC and the ATMega32 AVR. The parameters for serial communications require optimisation based on the clock frequency. In this case, it is for a 16 MHz clock.

These files enable the programmer to display information in HyperTerminal using the “printf” function. Therefore, if you plan to use this function then you need to include these files in your project.

The function “uart_init()” exists in the file “uart.c” and must be called once in the main project before “printf” can be used.

My Project File

Unzip it and double click on serialport.aps file which will start AVR Studio with the project files already set up for you. If you use this package then you will not need to add the linker options as described below as they are automatically set by the project file.

ATMega32 UART PC Interface - Testing schematics

Serial port project files:

Serial Port Communication Code

  1: /********************************************
  2: Author:Peter J. Vis
  3: Last Updated:8 Dec 2009
  5: Microcontroller:ATmega32
  6: Crystal:16 MHz
  7: Platform:Development System
 10: No portion of this work can be used in
 11: commercial applications without prior written
 12: permission. This work cannot be used by
 13: bloggers for web publishing.
 17: To test the UART interface communication
 18: with a PC, by sending characters to Windows
 19: HyperTerminal.
 22: UART PC Communication Interface using a MAX232.
 24: *********************************************/
 26: #define F_CPU 16000000UL
 28: #include <avr/io.h>
 29: #include <util/delay.h>
 30: #include "uart.h"
 31: #include "uart.c"
 33: int main()
 34: {
 35:  // Initialise UART - This function is
 36:  // in the file uart.c. This file is needed to
 37:  // make printf work when sending characters
 38:  // to HyperTerminal.
 40:  uart_init();
 43:  // Initialise HyperTerminal by sending
 44:  // VT100 escape sequences.
 45:  printf("\x1B[2J\x1B\x63");
 47:  // Print a welcome message.
 48:  printf("Would you like to play a game? \r\n");
 50: }

Read more: ATMega32 UART PC Interface – Testing

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top