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 are also very difficult. So i decided to switch to the arduino ide. Some body added Atmega162 support to arduino ide, so i utilized 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, but 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 some one. 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 full description of the registers and code i recommend to see the data sheet.
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 Serial Communication with FT232(USB to Uart Interface)
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.
Watch the Project Video Here.
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