how to calculate ubrrl

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi everybody,
i have to calculate ubrrl, when ubrr is above 256. their was a special formula for it. im searching on many forums for 1 hour now. i found nothing. and what was the max. for ubrrh 256 or 255?

greetings,
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings and welcome to AVR Freaks!

 

This is a standard-issue "fundamentals" question.

 

For UBRR values from 0 to 255, UBRRH = 0 (or 0x00, same thing) and the entire value is held in URBBL. That is because 255 = 0xff which just fits into 8 bits.

 

For larger values, some "overflows" into UBRRH. 

 

The common wisdom is just forget about high and low registers if you are using C and write UBRR = value; the compiler will automatically put the necessary parts in the proper places.

 

Same goes for 16 bit timer registers and the value generated by the ADC.

 

By the way, do you have this in the correct forum? Is this really about xMega?

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Dec 21, 2019 - 11:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

To use the UBRR formula, we need to know your AVR device type, your AVR system clock speed, and your desired baud rate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for your responds, its xmega32 and i need timer 1 and timer 0. and forgive my typo i meant ubrrh. i need to know how to calculate ubrrh blush the baud and systemclockspeed may can change but lets say 14400 Baud and 10MHz speed.

Last Edited: Tue. Dec 24, 2019 - 05:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jewlord wrote:
... its xmega32 ...

Atmel AVR XMEGA E Manual

[page 290]

21.10 Fractional Baud Rate Generation

due to

AVR1307: Using the XMEGA USART

[page 4]

2.1.3 Baud rate selection

in AN_8049 AVR1307: Using the XMEGA USART

via ATxmega32E5 - 8-bit PIC Microcontrollers

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you for your respond. i know ubrr for bsacle=0 for u2x=0 is systemclockspeed/(16*baud) -1 and for u2x=1 it is systemclockspeed/(8*baud) -1. and if the value is over 255 (if i remember correctly) you had to subtract the value with 255 and the you had to use a formula. but i cant find the formula anywhere. i may have to calculate it during my exam, otherwise the excel table is good too. i apologize for all the circumstances :D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The formula  SHOULD be in the two references that gchapman provided. See Eqn 2.1 of the second reference. It tells you all you need.

 

What appears to be the problem, here, is the inability to grasp using two registers to hold a 16 bit value (well, 12 bits in this case). Methinks you need to get those fundamentals under your control, first.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Tue. Dec 24, 2019 - 09:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure if it helps but perhaps think of a value like 12345. If you look at that in hex it is 0x3039 so if you were splitting this into H and L registers you'd simply put 0x30 into H and 0x39 into L. What's really going on is /256 and %256.0x30 (48) is 12345/256 and 0x39 is the remainder or 12345%256