Hello

Welcome lekule blog

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation.
together in the world. #lekule86
Join us on

AVR Microcontroller (Atmel 8) Serial Communication USART Configuration

Microcontroller is a control device that contains a number of peripherals like RAM, ROM TIMERS, serial data communication, etc., which are required to perform some pre-defined tasks. Nowadays, advanced type of microcontrollers are used in a wide variety of applications as per their capability and feasibility to perform some desired tasks and these controllers include 8051, AVR and PIC microcontroller. In this article, we are going to learn about advanced AVR family microcontroller and its programming.

AVR Microcontroller

The AVR is a type of controlling device manufactured by the Atmel Corporation in 1996. The AVR does not stand for anything, it is just a name. The AVR microcontrollers consist of the Harvard architecture, and therefore, the device run very fast with a reduced number of machine level instructions (RISC). The AVR microcontrollers consist of special features compared with other microcontroller such as 6-sleep modes, inbuilt ADC, internal oscillator and serial data communication, etc. The AVR microcontrollers are available in different configurations of 8-bit, 16-bit, and 32-bit to perform various operations.

AVR Microcontroller
AVR Microcontroller

USART Serial Data Communication in AVR Microcontroller

The USART stands for universal synchronous and asynchronous receiver and transmitter. It is a serial communication of two protocols. This protocol is used for transmitting and receiving the data bit by bit with respect to clock pulses on a single wire. The AVR microcontroller has two pins: TXD and RXD, which are specially used for transmitting and receiving the data serially. Any AVR microcontroller consists of USART protocol with its own features.

USART Communication in AVR Microcontroller
USART Communication in AVR Microcontroller


The Main Features of AVR USART
  • The USART protocol supports the full-duplex protocol.
  • It generates high resolution baud rate.
  • It supports transmitting serial data bits from 5 to 9 and it consists of two stop bits.

USART Pin Configuration

The USART of AVR consists of three Pins:
  • RXD: USART receiver pin (ATMega8 PIN 2; ATMega16/32 Pin 14)
  • TXD: USART transmitter pin (ATMega8 PIN 3; ATMega16/32 Pin 15)
  • XCK: USART clock pin (ATMega8 PIN 6; ATMega16/32 Pin 1)

Modes of Operation
The AVR microcontroller of USART protocol operates in three modes which are:
  • Asynchronous Normal Mode
  • Asynchronous Double Speed Mode
  • Synchronous Mode
Modes of Operation
Modes of Operation


Asynchronous Normal Mode

In this mode of communication, the data is transmitted and received bit by bit without clock pulses by the predefined baud rate set by the UBBR register.


Asynchronous Double Speed Mode

In this mode of communication, the data transferred at double the baud rate is set by the UBBR register and set U2X bits in the UCSRA register. This is a high-speed mode for synchronous communication for transmitting and receiving the data quickly. This system is used where accurate baud rate settings and system clock are required.


Synchronous Mode

In this system, transmitting and receiving the data with respect to clock pulse is set UMSEL=1 in the UCSRC register.

USART Configuration In AVR microcontroller

USART can be configured using five registers such as three control registers, one data register and baud-rate-selection register, such as UDR, UCSRA, UCSRB, UCSRC and UBRR.


7 Steps for Composing the Program


Step1: Calculate and Set the Baud Rate


The baud rate of USART/UART is set by the UBRR registrar. This register is used to generate the data transmission at the specific speed. The UBRR is a 16-bit register. Since the AVR is a 8-bit microcontroller and its any register size is 8-bit. Hence, here the 16-bit UBRR register is composed of two 8-bit registers such as UBRR (H), UBRR(L).


The formula of the baud rate is

BAUD= Fosc/(16*(UBBR+1))

The formula of the UBRR register is

UBRR= Fosc/( 16*(BAUD-1))

The frequency of the AVR microcontroller is 16MHz=16000000; Let us assume the baud rate as 19200Bps, then

UBRR= 16000000/(16*(19200-1))
UBRR= 16000000/(16*(19200-1))
UBRR= 51.099

Eventually find the baud rate

BAUD= 16000000/( 16*(51+1))
UBRR= 19230bps


Step2: Data Mode Selection

The data transmission mode, start bit and stop bit and the character size is set by the control and status register UCSRC.

Data Mode Selection
Data Mode Selection


Step3: Data Transmission Mode Selection
The synchronous and asynchronous mode is selected by the UMSEL bit of the control status register. If we give UMSEL=0, then the USART operates in asynchronous mode, otherwise operates in synchronous mode.
Data Transmission Mode Selection
Data Transmission Mode Selection


Step4: Start Bit and Stop Bit

The start bit and stop bits are a way for sending and receiving the data serially. Generally any data fame consists of one stat bit and one stop bit, but the AVR microcontroller has one start bit and two stop bits for processing the data. The extra stop bit can be useful for adding a little extra receive processing time. It is especially useful for high data transfer rates, whereas the data transfer speed is very high, so we don’t get proper data. Thus, we can increase the processing time by using two stop bits to get the proper data.

Start Bit and Stop Bit
Start Bit and Stop Bit

The number of stop bits is selected by the USBS bit of UCSRC – the control status register. The USBS=0, for one stop bit, and USBS=1, for two stop bits.

Step5: Set the Character Size

As in case with the basic microcontrollers sending and receiving the byte of data(8-bits) at a time, whether in a AVR microcontroller, we can choose a data frame format in each frame by the UCSZ bit of the UCSRC register.
Data Frame Format
Data Frame Format


Step6: Store the Received Data


The AVR microcontroller consists of a UDR buffer register for transmitting and receiving data. The UDR is a 16-bit buffer register wherein 8-bits are used for receiving (RXB) the data and other bits are used for transmitting the data (TXB). Transmitting data buffer register will be the destination to UDR register for the written data on its location. Receiving data buffer register will be returning the content of the UDR register.


Step7: Transmitter and Receiver Enabling
The transmitted and received data will be allowed by the RXC and TXC pins of the microcontroller which are set by the UCSRA register of the microcontroller. This flag bit set by the microcontroller for the data is completed by receiving and transmitting (TXC=RXC=1).



Double the Baud Rate


We can double the transfer rate of the USART communication of the AVR microcontroller from 16 bits to 8-bits effectively by the U2X –bit in the UCSRA register. This bit effects only on asynchronous operation. If we can set this bit (U2X=1), it will reduce the baud rate from 16-bit to 8-bit effectively doubling the transfer rate for synchronous communication.


This is an advanced feature of the AVR microcontroller for speedy processing of the data.


USART Program






Every microcontroller is predefined with a specific IDE,  and based on this IDE, microcontrollers are programmed with embedded C or assembly language. The AVR microcontroller programming is developed by the AVR studio. Furthermore, If you want additional information about the steps to build microcontroller based projects, or detailed information on this topic, you can contact us by commenting below.

Share this:

ABOUTME

Hi all. This is deepak from Bthemez. We're providing content for Bold site and we’ve been in internet, social media and affiliate for too long time and its my profession. We are web designer & developer living India! What can I say, we are the best..

Post a Comment
My photo

Hi, I`m Sostenes, Electrical Technician and PLC`S Programmer.
Everyday I`m exploring the world of Electrical to find better solution for Automation. I believe everyday can become a Electrician with the right learning materials.
My goal with BLOG is to help you learn Electrical.

Labels

LEKULE TV EDITORIALS ARTICLES DC ROBOTICS DIGITAL SEMICONDUCTORS GENERATOR AC EXPERIMENTS MANUFACTURING-ENGINEERING REFERENCE FUNDAMENTAL OF ELECTRICITY ELECTRONICS ELECTRICAL ENGINEER MEASUREMENT TRANSDUCER & SENSOR VIDEO ARDUINO RENEWABLE ENERGY AUTOMOBILE TEARDOWN SYNCHRONOUS GENERATOR DIGITAL ELECTRONICS ELECTRICAL DISTRIBUTION CABLES AUTOMOTIVE MICROCONTROLLER SOLAR PROTECTION DIODE AND CIRCUITS BASIC ELECTRICAL ELECTRONICS MOTOR SWITCHES CIRCUIT BREAKERS CIRCUITS THEORY PANEL BUILDING ELECTRONICS DEVICES MIRACLES SWITCHGEAR ANALOG MOBILE DEVICES WEARABLES CAMERA TECHNOLOGY COMMUNICATION GENERATION BATTERIES FREE CIRCUITS INDUSTRIAL AUTOMATION SPECIAL MACHINES ELECTRICAL SAFETY ENERGY EFFIDIENCY-BUILDING DRONE CONTROL SYSTEM NUCLEAR ENERGY SMATRPHONE FILTER`S POWER BIOGAS BELT CONVEYOR MATERIAL HANDLING RELAY ELECTRICAL INSTRUMENTS ENERGY SOURCE PLC`S TRANSFORMER AC CIRCUITS CIRCUIT SCHEMATIC SYMBOLS DDISCRETE SEMICONDUCTOR CIRCUITS WIND POWER C.B DEVICES DC CIRCUITS DIODES AND RECTIFIERS FUSE SPECIAL TRANSFORMER THERMAL POWER PLANT CELL CHEMISTRY EARTHING SYSTEM ELECTRIC LAMP FUNDAMENTAL OF ELECTRICITY 2 BIPOLAR JUNCTION TRANSISTOR 555 TIMER CIRCUITS AUTOCAD BLUETOOTH C PROGRAMMING HOME AUTOMATION HYDRO POWER LOGIC GATES OPERATIONAL AMPLIFIER`S SOLID-STATE DEVICE THEORRY COMPUTER DEFECE & MILITARY FLUORESCENT LAMP INDUSTRIAL ROBOTICS ANDROID ELECTRICAL DRIVES GROUNDING SYSTEM CALCULUS REFERENCE DC METERING CIRCUITS DC NETWORK ANALYSIS ELECTRICAL SAFETY TIPS ELECTRICIAN SCHOOL ELECTRON TUBES FUNDAMENTAL OF ELECTRICITY 1 INDUCTION MACHINES INSULATIONS USB ALGEBRA REFERENCE HMI[Human Interface Machines] INDUCTION MOTOR KARNAUGH MAPPING USEUL EQUIATIONS AND CONVERSION FACTOR ANALOG INTEGRATED CIRCUITS BASIC CONCEPTS AND TEST EQUIPMENTS DIGITAL COMMUNICATION DIGITAL-ANALOG CONVERSION ELECTRICAL SOFTWARE GAS TURBINE ILLUMINATION OHM`S LAW POWER ELECTRONICS THYRISTOR BOOLEAN ALGEBRA DIGITAL INTEGRATED CIRCUITS FUNDAMENTAL OF ELECTRICITY 3 PHYSICS OF CONDUCTORS AND INSULATORS SPECIAL MOTOR STEAM POWER PLANTS TESTING TRANSMISION LINE C-BISCUIT CAPACITORS COMBINATION LOGIC FUNCTION COMPLEX NUMBERS CONTROL MOTION ELECTRICAL LAWS INVERTER LADDER DIAGRAM MULTIVIBRATORS RC AND L/R TIME CONSTANTS SCADA SERIES AND PARALLEL CIRCUITS USING THE SPICE CIRCUIT SIMULATION PROGRAM AMPLIFIERS AND ACTIVE DEVICES APPS & SOFTWARE BASIC CONCEPTS OF ELECTRICITY CONDUCTOR AND INSULATORS TABLES CONDUITS FITTING AND SUPPORTS ELECTRICAL INSTRUMENTATION SIGNALS ELECTRICAL TOOLS INDUCTORS LiDAR MAGNETISM AND ELECTROMAGNETISM PLYPHASE AC CIRCUITS RECLOSER SAFE LIVING WITH GAS AND LPG SAFETY CLOTHING STEPPER MOTOR SYNCHRONOUS MOTOR AC METRING CIRCUITS BECOME AN ELECTRICIAN BINARY ARITHMETIC BUSHING DIGITAL STORAGE MEMROY ELECTRICIAN JOBS HEAT ENGINES HOME THEATER INPECTIONS LIGHT SABER MOSFET NUMERATION SYSTEM POWER FACTORS REACTANCE AND IMPEDANCE INDUCTIVE RECTIFIER AND CONVERTERS RESONANCE SCIENTIFIC NOTATION AND METRIC PREFIXES SULFURIC ACID TROUBLESHOOTING TROUBLESHOOTING-THEORY & PRACTICE 12C BUS APPLE BATTERIES AND POWER SYSTEMS DC MOTOR DRIVES ELECTROMECHANICAL RELAYS ENERGY EFFICIENCY-LIGHT INDUSTRIAL SAFETY EQUIPMENTS MEGGER MXED-FREQUENCY AC SIGNALS PRINCIPLE OF DIGITAL COMPUTING QUESTIONS REACTANCE AND IMPEDANCE-CAPATIVE SEQUENTIAL CIRCUITS SERRIES-PARALLEL COMBINATION CIRCUITS SHIFT REGISTERS WIRELESS BUILDING SERVICES COMPRESSOR CRANES DIVIDER CIRCUIT AND KIRCHHOFF`S LAW ELECTRICAL DISTRIBUTION EQUIPMENTS 1 ELECTRICAL DISTRIBUTION EQUIPMENTS B ELECTRICAL TOOL KIT ELECTRICIAN JOB DESCRIPTION INDUSTRIAL DRIVES LAPTOP SCIENCE THERMOCOUPLE TRIGONOMENTRY REFERENCE UART oscilloscope BIOMASS CONTACTOR ELECTRIC ILLUMINATION ELECTRICAL SAFETY TRAINING ELECTROMECHANICAL FEATURED FILTER DESIGN HARDWARE JUNCTION FIELD-EFFECT TRANSISTORS NASA NUCLEAR POWER VALVE COLOR CODES ELECTRIC TRACTION FLEXIBLE ELECTRONICS FLUKE GEARMOTORS INTRODUCTION LASSER PID PUMP SEAL ELECTRICIAN CAREER ELECTRICITY SUPPLY AND DISTRIBUTION MUSIC NEUTRAL PERIODIC TABLES OF THE ELEMENTS POLYPHASE AC CIRCUITS PROJECTS REATORS SATELLITE STAR DELTA VIBRATION WATERPROOF