go_away

Author Topic: Setting Baud Rate using the UBRR register on AtMega8?  (Read 2993 times)

0 Members and 2 Guests are viewing this topic.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Setting Baud Rate using the UBRR register on AtMega8?
« on: June 28, 2011, 08:03:15 PM »
So this one is throwing me for a loop.

The UBRR register is a 12 bit register with 4 bits in UBRRH and 8 bits in UBRRL.  The entire UBRR register is used to set the baud rate for UART.

The 4 bits in UBRRH contain the 4 most "significant" bits.  So, let's say I'm running at 1MHz and want a baud rate of 2400.  The data sheet says to set UBRR to 25.  In hex that is 000000011001.(12 bits remember?)  So, would I put 1100 in the 4 bits in UBRRH and 10000000 in UBRRL?  Or would I put 0000 in UBRRH and 00011001 in UBRRL?  The second way makes more sense.

Is saying "the most significant bits" their way of saying "these 4 bits come to the left of the 8 bits below."?

Ah, just googled "most significant bit".  Seems that ACTUALLY means something and isn't their way of saying something else...

Whatever, I'll leave this thread up there for search since I didn't find anything similar.  

Offline TrickyNekro

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,207
  • Helpful? 15
  • 1.6L Peugeot 307 tuner
Re: Setting Baud Rate using the UBRR register on AtMega8?
« Reply #1 on: June 29, 2011, 07:07:25 AM »
In hex that is 000000011001.(12 bits remember?)

First of all that's binary, in HEX it is Hx019

Your second - "makes more sense" guess is correct. To clarify this to you most and least important bits goes like this.

(most important)(least important) = number

By most important we mean that if something changes there, then the number is gonna change a lot.
By least important, on the other hand, we mean that if something changes then the number is gonna change little.

And that's a good way to remember it.

so if I have let's say this number:

0000 00000001 that equals 1

if I change something in the least important byte, for example:
0000 00100001 that equals 33

But if I change something in the most important byte, it will go like this:

0010 00000001 that equals 513

So if you want a small number (less than 255) you try changing the least significant byte
If you need a number greater than 255 then you change both most and least significant bytes to "build" that number.

Capitsi?

Best Regards, Lefteris
Greece
For whom the interrupts toll...


P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: Setting Baud Rate using the UBRR register on AtMega8?
« Reply #2 on: June 29, 2011, 02:45:45 PM »
Yeah I don't know why I was confused.

I was thinking significant figures from science in college.  So for a number like this 00034566, the sig figs would only be 34566.  Different terminology I guess.


 


Get Your Ad Here