PIC UART Baud Rate Calculator

Use the calculator below to determine the register values needed for a given baud rate and clock frequency. Note that older PIC’s may not feature an extended UART module (EUSART), which allows a 16-bit baud rate generator to be activated via BRG16 configuration bit.

If your microcontroller does not feature a EUSART module, only use the results from the table where BRG16 = 0.


BRGH BRG16 Multiplier (x) SPBRG Actual Baud Baud Error (%)
0 0 64 6 8928.57 7.52
0 1 16 25 9615.38 -0.16
1 0 16 25 9615.38 -0.16
1 1 4 103 9615.38 -0.16

Explanation:

The formula to calculate a given baud rate for a given is: $$\text{BAUD} = {f_{osc}\over {x(\text{SPBRG} + 1)}}$$ Where:

To find the Baud rate, we need solve for the SPBRG value. After solving we get:

$$ \text{SPBRG} = {f_{osc}\over{x(\text{BAUD})} }-1$$

Usually fOSC and BAUD is already known. The only unknown left is x, the divisor for the baud rate generator. The table solves this issue by calculating every possible value of x.

Unfortunately the result for SPBRG will almost always be a fraction. The SPBRG register can only accept integers. This will leave an error in the baud rate after rounding up or down. The only step left is to pick a BRGH, BRG16, and an SPBRG value that gives the least amount of error.

The formula to calculate baud error is: $$ Error = {\text{Actual Baud Rate} - \text{Desired Baud Rate} \over \text{Desired Baud Rate}} $$

Tips:

SPBRG to SPBRGH:SPBRGL

With EUART enabled devices, SPBRG is typically split into two 8-bit registers, SPBRGH, and SPBRGL. If the result is larger than 255, the SPBRG result will need to be converted into their respective SPBRGH and SPBRGL values:

// For Example in C, say the result for SPBRG = 64206 (or 0xFACE in hexadecimal)
result = 0xFACE;
SPBRGH = (result >> 8); // 0xFA will be loaded in SPBRGH
SPBRGL = result & 0xFF; // 0xCE will be loaded in SPBRGL
Easy Zero Baud Rate Error

Under 2% baud error is typically acceptable, but it depends on the device. If you need to get the baud rate as low as possible. Consider using an external oscillator that is perfectly divisible by the baud rate, such as: 3.6864 MHz, 7.3728 MHz, 11.0592 MHz, 14.7456 MHz, etc.