Comunicação serial Atmega162 UAR usando Arduino IDE

Atmega162 UAR serial communication using Arduino IDE

I started working on a project that involves the Atmega162 to be programmed to achieve the desired result. I started writing code using Atmel Studio ide, but I found it very difficult to work with Atmel Studio ide. Atmel studio is slow and encountering bugs etc. It's also very difficult. So I decided to switch to the Arduino ide. Someone added Atmega162 support to the Arduino ide, so I used that. To install Atmega162 support on your Arduino ide, see my post.
Atmega162 with Arduino Ide

Although it added atmega162 support to the Arduino ide, it lacks serial interface (uart) support. The UART initialization and data sending commands Seial.begin and Serial.send did not work if you used the above support provided by someone. So I decided to operationalize the atmega162 UART microcontroller through individual register configuration. I created a separate header file for UART initialization and work “Uart.h”. In uart.hi defined the values ​​for individual uart registers. Uart initialization code in c++ and assembly is provided in the atmega162 datasheet. Almost all atmega UARTS series microcontrollers are initialized using the same registers, the registers are the same for almost all microcontrollers. I copied the initialization code from there. For a complete description of the records and code, I recommend seeing the technical sheet.

Atmega162 uart initialization, register value calculation formula.

Atmega162 uart initialization, register value calculation formula.
The most important register in Uart initialization is UBRR. It is a 16-bit register. Divided into two 8-bit registers UBRRL and UBRRH. To set the desired baud rate. We have to calculate the value of this record. The formula to calculate the value is given on the right side. “Baud Rate” is the desired baud rate we need. Fpb is the clock/crystal frequency at which the microcontroller is running. UxBRG is a 16-bit UBRR register. After calculating the value, load the highest 8 bits into UBRRH and the lowest 8 bits into UBRRL.

Atmega162 serial communication with MAX232 (Rs232 interface)

Atmega162 Uart serial communication using Max232 level converter

Atmega162 Uart serial communication using Max232 level converter

Atmega162 serial communication with FT232 (USB to Uart interface)

Atmega162 Uart serial communication using ft232 USB to Uart level converter

Atmega162 Uart serial communication using ft232 USB to Uart level converter

Atmega162 has 2 uarts 0 and 1. I am using uart-0 for this post. You can use uart-1 if you want. Uart-0 is on pins 10,11 and Uart-1 is on pins 3,4. In the demo project I initialized the baud rate to 9600. I am sending my website name from the atmega162 serial port to my pc (personal computer). To view the output on my computer, I'm using putty.

A status LED is connected to pin #25. It blinks every second. Shows the status of the program, whether the hardware is working or not. Note: The LED is connected to pin no. 25 where as in the code it is declared as pin no. 22, this is because for programming the pins are assigned different numbers. Remember the top tutorial, see this for more clarification.

Since the boot manager written for atmega162 didn't work for me. then I directly load the code from the arduino ide to the atmega162 microcontroller using an external USBasp programmer.
Download the project's .ino file. The code is written in Arduino IDE. Please provide us with your feedback on the project.

Watch the project video here.

Atmega162 microcontroller uart files
More Uart serial communication projects using different types of microcontrollers. Each project contains free source code and circuit diagram of the project. The list of tutorials is below


Serial communication using Uart of 8051 microcontroller(89c51,89c52)
Serial communication using Uart of Microchip Pic16f877 microcontroller
Serial data transmission using 89c51 communication
RS485 serial communication between Arduino Uno and Leonardo
​Serial communication using Atmega32A
Serial data received from PC using Microchip Pic Microcontroller

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.