0% found this document useful (0 votes)
38 views23 pages

Programming USART Using AVR Microcontroller

Programming USART using AVR Microcontroller

Uploaded by

Azam Rafique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views23 pages

Programming USART Using AVR Microcontroller

Programming USART using AVR Microcontroller

Uploaded by

Azam Rafique
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Mehran University of Engineering &

Technology, Jamshoro
Department of Telecommunication
Engineering

Programming USARTs

By:

Engr. Azam Rafique


Instrumentation Engineer
TQCIC, IIT Building, MUET,
Jamshoro, Pakistan
email: [email protected]

Serial Vs Parallel Communication

Serial Communication

Baud Rates
Baud Rate is synonymous to symbols per second or pulses per

second. It is the unit of symbol rate, also known as baud or


modulation rate; the number of distinct symbol changes
(signaling events) made to the transmission medium per second
in a digitally modulated signal or a line code.
Some standard baud rates are

1200
2400
4800
9600
19200
38400
57600
115200

RS-232 Protocol
RS 232 Voltage levels
-3 to -25 (Logic HIGH)
+3 to +25
(Logic LOW)
Data bit sequence
IDEAL (Logic HIGH)
Start bit (Logic LOW)
First bit as LSB (B0)
.
.
.
8th bit as MSB (B7)
Parity bit (if pre-set in settings)
Stop bits (can be 1 or 2 depends on settings)

RS-232 Protocol (cont)

TTL Logic Voltage Levels

Serial Communication in AVR

Serial Communication between TTL


devices

Programing in AVR
Registers:
UDR (USART Data Register)
UBRRL & UBRRH Register (16-bit)

Used to set baud rate

UCSRA (USART Control and Status Register-A)


UCSRB (USART Control and Status Register-B)

UCSRC (USART Control and Status Register-C)

Used to control flow of USART

Setting Baud Rate (UBRR)


To set Baud Rate:
Desired Baud rate = Fosc / (16(X+1))
X=(Fosc / 16 (Desired Baud Rate) ) - 1

Where:
Fosc = Oscillator Frequency
X is the value to be loaded in UBRR Register
Desired Baud rate can be any from:
1200
2400
4800
9600
19200
38400
57600
115200

Setting Baud Rate

UBRR

URSEL = 0
URSEL = 1

UBRRH
UCSRC

UCSRA

UCSRB

UCSRC

Working Steps:
1. Select Baud Rate (UBRR)
2. Enable TX/RX or Both (UCSRB)
3. Select Character size - default is 8 (UCSRC)
For Transmission:
Check if UDRE (Transmission Buffer) is empty, if yes,
load data to UDR
For Receiving:
Check if RXC (Receive Complete), if yes, copy data from
UDR

USART
Transmit
Program
#include "avr/io.h"
int main()
{
UBRRL=0x33;
UCSRB=0x18;
UCSRC=0x86;
DDRB=0xFF;
while(1)
{
if(UCSRA & (1 << 5))
UDR = 'A';

if(UCSRA & (1 << 7))


PORTB=UDR;
}
return 0;
}

Proteus Schematic

Proteus Results

2. Transmit ABC using USART @


BR=1200
3. Transmit ABC using Arrays @ BR=1200;
4. Receive data from USART, if data is ON then turn

PD5=1, if data received is OF then turn PD5 OFF.


5. Receive data from USART, if data is ON then turn
PD5=1, if data received is OFF then turn PD5 OFF.

You might also like