Hi Guys
Today we will see about AVR Atmega16 USART
communication.
In this we
are using F_CPU = 8MHz; for the USART communication we should initialize
proper Baud Rate.
To Enable USART:
1.) Baud Rate should be set.
2.) Initialize Control register for 8bit
data transfer
We take Baud
Rate as 9600
For F_cpu = 8Mhz
and Baud Rate 9600 we should enter the value of UBRR value as shown in
Table above i.e.: 51 in decimal so in we must enter 33 Hex Value.
U2X = 0
means asynchronous and U2X = 1 means synchronous.
We are using
asynchronous transmission.
There are 3
control register and 1 data register for USART
Control
Register:
1.) UCSRA
2.) UCSRB
3.) UCSRC
Data
Register:
1.) UDR
Control
Register:
1.) UCSRB & UCSRC:
In this
Register we should enable TXEN and
RXEN bit by setting it 1(high).
And there is
bit UCSZ2
bit with used to set whether it’s a 8 bit transmission or 9 bit transmission.
UCSZ2 combine with two other bit UCSZ1 and UCSZ0
in Register UCSRC are used to set it the Table show the setting.
We are using
the Character Size as 8 bit, so UCSZ2-UCSZ0 = 011
In UCSRC
Register there is bit URSEL which is used to access the UBRR Register and UCSRC
Register if Set 0 means UBRR (initially its UBRR Register) and when set 1 we
can use UCSRC Register. Thus to set 8bit transmission we should 1st
set URSEL bit.
2.) UCSRA:
U2X = 0
because we are using Asynchronous mode.(Initially it is 0)
3.) UDR:
This is a
Data register for USART it convert Serial data (8 bit) into Parallel (8 bit)
data and vice versa.
Is used to for transmitting and receiving the data
from TXD and RXD Pin.
For More details:
Refer Videos
code:
No comments:
Post a Comment