Navigation Bar

Calculators: XMEGA Baud Rate

Back to Calculator Index

Recently I've taken an interest in Atmel's XMEGA series AVR microcontrollers. However, their documentation has taken a sharp decline in quality, from the verbose and easy reading ATmega series, down to this cryptic, discombobulated format they're now using. I appreciate the part about grouping peripherals by IO bank, but I keep looking and looking and nowhere do they spell out what the registers are actually named. They might give three different possible names—the section title, the table heading, the bit names—and yet the actual term, found deep within the nested io.h file, is still something else.

This specific calculator concerns the USART peripherals: as near as I can tell, this is what they meant to write, but somehow never got around to doing?

To correct this injustice, the below provides: a set of closed-form equations, which can be applied immediately; a JavaScript calculator that uses the equations; and the necessary code examples to use them (C and ASM, though a disclaimer: the ASM is untested).

 

Calculation

Enter new numbers and see the remaining output values change:

Peripheral Clock Frequency fper = Hz
Desired Baud Rate fbaud = bps
Half Clock CLK2X = 1
USART Port and Instance
BSCALE =
 
BSEL =
 
Foobar

Code Example - C

    USARTC0.CTRLB |= USART_CLK2X_bm;
    USARTC0.BAUDCTRLA = (4039 & 0xff) << USART_BSEL_gp;
    USARTC0.BAUDCTRLB = ((-7) << USART_BSCALE_gp) | ((4039 >> 8) << USART_BSEL_gp);

 

Code Example - Assembly

    ld r16, USARTC0.CTRLB
    ori r16, USART_CLK2X_bm
    st USARTC0.CTRLB, r16
    ldi r16, (4039 & 0xff) << USART_BSEL_gp
    st USARTC0.BAUDCTRLA, r16
    ldi r16, ((-7) << USART_BSCALE_gp) | ((4039 >> 8) << USART_BSEL_gp)
    st USARTC0.BAUDCTRLB, r16

 

Equation

\[ \texttt{BSCALE} = \left\lceil \log_2 \left( \frac{f_\textit{\scriptsize per}}{16 f_\textit{\scriptsize baud}} - 1 \right)  \right\rceil \] \[ \texttt{BSEL} = 2^\texttt{\scriptsize -BSCALE} \left( \frac{f_\textit{\scriptsize per}}{16 f_\textit{\scriptsize baud}} - 1 \right) \]

These formulas are related to the equations shown on Page 204, rearranged to solve for the register values.

 

Back to Calculator Index

 

Copyright Notice