Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Atmega162 UAR serial communication using Arduino IDE

By EG Projects February 15, 2021

I started working on a project with involves Atmega162 to be programmed in order to achieve the desired output. I started to write code using Atmel studio ide but I found it very hard to work with the Atmel studio ide. Atmel studio is slow and finding bugs etc is also very difficult. So I decided to switch to the Arduino ide. Somebody added Atmega162 support to Arduino ide, so I used it. In order to install the Atmega162 support to your Arduino ide please see my post.
Atmega162 with Arduino Ide 

Although he added the atmega162 support to Arduino ide, the support lacks the serial interface(uart). UART initialization and data sending commands Seial.begin() and Serial.send() did not work if using the above support provided by someone. So I decided to ope-rationalize the atmega162 microcontroller UART by individual register configuration. I made a separate header file for UART initialization and working “Uart.h”.  In uart.h i defined the values for individual uart registers. Uart initialization code in c++ and assembly is given in the atmega162 datasheet. Almost all the atmega series microcontrollers UARTS are initialized using the same registers, the registers are same for almost all the microcontrollers. I copied the initialization code from there. For a full description of the registers and code, I recommend seeing the datasheet.

Atmega162 uart initialization, register values calculation formula.

Atmega162 uart initialization, register values calculation formula.
Most important register in initializing Uart is UBRR. Its a 16 bit register. Divided in to two 8- bit registers UBRRL and UBRRH. In order to set the desired baud rate. We have to calculate the value for this register. The formula for calculating the value is given on right side. “Baud Rate” is the desired baud rate that we need. Fpb is the clock/crystal frequency on which the microcontroller is working. UxBRG is UBRR 16-bit register. After calculating the value, upload the higher 8-bits in UBRRH and lower 8-bits in 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 the uart-1 if you want. Uart-0 is at pins#10,11 and Uart-1 is at pin#3,4. In the demo project i initialized the baud rate to 9600. I am sending my website name from atmega162 serial port to my pc(personal computer). For viewing the output on my computer i am using an putty.  ​

A status led is connected to pin#25. It blinks after every second. Shows the program status, if the hardware is working or not. Note: The led is connected to pin#25 where as in code its declared as pin#22, its because for programming the pins are assigned different numbers. Remember the upper tutorial see that for more clarification.

Since the boot loader written  for atmega162 does not worked for me. so i directly upload the code from arduino ide to atmega162 microcontroller using an external USBasp programmer.
Download the project .ino file. Code is written in arduino ide. Please provide us your feed back on the project.

 

Watch the Project Video Here.

Atmega162 microcontroller uart files 
More Projects on Serial Uart Communication using different types of microcontrollers. Each project contains free source code and circuit diagram of the project. Tutorials list is below
​

Serial Communication using Uart of 8051(89c51,89c52) microcontroller
Serial Communication using Uart of Pic16f877 Microchip microcontroller
​
Serial data Transmission using 89c51 Communication
​
Serial rs485 communication between arduino uno and leonardo
​
Serial Communication using Atmega32A
Serial data received from pc using Microchip Pic Microcontroller

You may also like:


  • How does LoRa modulation enable long-range communication?

  • What are the top tools for developing embedded software?

  • What is the Modbus protocol and how does it work?

  • What is a Robot Operating System (ROS)?

  • How to read input from USB keyboard on Arduino
  • Getting Started With Arduino With Simple LED Blinking Code Circuit Setup On Breadboard
    Getting started with Arduino – (Part 1/49)

Filed Under: AVR, Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe