Navigation Bar

Calculators: XMEGA Baud Rate

Back to Calculator Index

Recently (as of 2015) I've taken an interest in Atmel's XMEGA series AVR microcontrollers. However, their documentation seems to have declined a bit, compared to the verbose and easy reading ATmega series. I appreciate the grouping peripherals by IO bank, but I keep looking and looking and nowhere do they spell out what precisely the registers are named. They might give three different possible names—the section title, the table heading, the bit names—and yet the actual names (found deep within the nested io.h files), is still something else... I have found a number of inconsistencies on given devices, too (registers that are named that don't exist, or omitted ones that do exist).

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?

So, here's 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), assuming you're using the official header files.

 

Calculation

Enter new numbers and see the remaining output values change:

Peripheral Clock Frequency fper = Hz
Desired Baud Rate fbaud = bps
Double 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