Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Baud rate setting of Atmega32

Status
Not open for further replies.

shahbaz.ele

Advanced Member level 1
Joined
Aug 12, 2008
Messages
454
Helped
72
Reputation
146
Reaction score
73
Trophy points
1,308
Location
Islamabad, Pakistan
Activity points
3,669
Dear all
I am using ATmega32 controller. serial port is interfaced here is code
Code:
baud = 12;

void rs_init(unsigned char baud)
{
UBRRL = baud;
UCSRC = (1<<URSEL)|(3<<UCSZ0);
UCSRB = (1<<RXEN) | (1<<TXEN);
}


void rs_send(unsigned char data)
{
while( !( UCSRA & (1<<UDRE)) );
UDR = data;
}

this code is working well.
baud rate 4800 at 1MHz

The problem is that now I want to set baud rate 9600 at 1Mhz how can I do this.
Is there any calculator of baud rate value for microcontroller speed?
 

The maximum supported baud rate by an AVR is the CPU clock divided by 8
so when using 1 MHz clock you can use 125K buad rate
the baud rate can be calculated using this equation(found in datasheet)

Baud = Fosc / (16*(UBRR + 1))


instead of changing the baud rate u can just set the double speed bit (U2X) in the UCSRA register


you realise that according to the equation your baud rate with your freqyency can generate errors
consider using 7.3728 or 11.0592 crystals to eliminate the error
 
Thanks you all
dear 3wais
after setting U2X, will it disturb my rest of code.
what do you mean by using 7.3728 or 11.0592 crystals, will it give errors by setting U2X bit.
I am not using any crystal at the moment
 

shahbaz.ele said:
after setting U2X, will it disturb my rest of code.
No this only has to do with the settings of USART. So don't worry, other peripherals will not be disturbed.

what do you mean by using 7.3728 or 11.0592 crystals, will it give errors by setting U2X bit.
I am not using any crystal at the moment
Those crystal values will give you no baudrate error according to the tables at pages 165-168. If you use the 8MHz internal RC, then you should look the table 70 in page 167 for 8Mhz clock. There is an error column for each clock frequency. So for 8MHz for example and double speed (U2X=1), 57.6K is not a good baudrate because you have an error of 2.1%. 38.4K on the other hand gives an error of 0.2%. Thus it is much more appropriate to choose 38.4K at 8MHz frequency.

http://www.atmel.com/Images/doc2503.pdf


Hope it helped,
Alexandros
 
thanks dear alexxx
how can I set 8 Mhz frequency. and 38.4K baud rate

---------- Post added at 12:13 ---------- Previous post was at 12:12 ----------

without using crystal
 

shahbaz.ele said:
how can I set 8 Mhz frequency
From the fuse bits:
Int RC Osc, start-up time: 6CK + 65 ms, [CKSEL=0010 SUT=10].
Also: "Divide clock by 8 internally" (CKDIV8) disabled.

and 38.4K baud rate
It is in table 70 of the datasheet. UBRR=25, U2X bit of UCSRA register = 1. Keep in mind that UBRR is a 16-bit register. So for values < 255 (like 25 for instance), UBRRH stays 0 and 25 goes to UBRRL.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top