28.3 EUSART Baud Rate Generator (BRG)

The Baud Rate Generator (BRG) is an 8-bit or 16-bit timer that is dedicated to the support of both the asynchronous and synchronous EUSART operations. By default, the BRG operates in 8-bit mode. Setting the BRG16 bit selects 16-bit mode.

The SPxBRGH:SPxBRGL register pair determines the period of the free-running baud rate timer. In Asynchronous mode, the multiplier of the baud rate period is determined by both the BRGH and the BRG16 bits. In Synchronous mode, the BRGH bit is ignored.

Table 28-1 contains the formulas for determining the baud rate. Equation 28-1 provides a sample calculation for determining the baud rate and baud rate error.

Typical baud rates and error values for various Asynchronous modes have been computed and are shown in the table below. It may be advantageous to use the high baud rate (BRGH = 1) or the 16-bit BRG (BRG16 = 1) to reduce the baud rate error. The 16-bit BRG mode is used to achieve slow baud rates for fast oscillator frequencies. The BRGH bit is used to achieve very high baud rates.

Writing a new value to the SPxBRGH:SPxBRGL register pair causes the BRG timer to be reset (or cleared). This ensures that the BRG does not wait for a timer overflow before outputting the new baud rate.

If the system clock is changed during an active receive operation, a receive error or data loss may result. To avoid this, check the status of the Receive Idle Flag (RCIDL) bit to make sure the receive operation is idle before changing the system clock.

Equation 28-1. Calculating Baud Rate Error

For a device with FOSC of 16 MHz, desired baud rate of 9600, Asynchronous mode, 8-bit BRG:

DesiredBaudrate=FOSC64×(SPxBRG+1)

Solving for SPxBRG:

SPxBRG=FOSC64×DesiredBaudrate1
SPxBRG=1600000064×96001
SPxBRG=25.04225
CalculatedBaudrate=1600000064×(25+1)
CalculatedBaudrate=9615
Error=CalculatedBaudrateDesiredBaudrateDesiredBaudrate
Error=961596009600
Error=0.16%
Table 28-1. Baud Rate Formulas
Configuration BitsBRG/EUSART ModeBaud Rate Formula
SYNCBRG16BRGH
0008-bit/AsynchronousFOSC/[64 (n+1)]
0018-bit/AsynchronousFOSC/[16 (n+1)]
01016-bit/Asynchronous
01116-bit/AsynchronousFOSC/[4 (n+1)]
10x8-bit/Synchronous
11x16-bit/Synchronous
Note: x = Don’t care, n = value of SPxBRGH:SPxBRGL register pair.
Table 28-2. Sample Baud Rates for Asynchronous Modes
Baud RateSYNC = 0, BRGH = 0, BRG16 = 0
FOSC = 32.000 MHzFOSC = 20.000 MHzFOSC = 18.432 MHzFOSC = 11.0592 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300
120012211.7325512000.0023912000.00143
240024040.1620724040.1612924000.0011924000.0071
960096150.16519470-1.363296000.002996000.0017
10417104170.0047104170.002910286-1.262710165-2.4216
19.2k19.23k0.162519.53k1.731519.20k0.001419.20k0.008
57.6k55.55k-3.55357.60k0.00757.60k0.002
115.2k
Baud RateSYNC = 0, BRGH = 0, BRG16 = 0
FOSC = 8.000 MHzFOSC = 4.000 MHzFOSC = 3.6864 MHzFOSC = 1.000 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
3003000.162073000.001913000.1651
120012020.1610312020.165112000.004712020.1612
240024040.165124040.162524000.0023
960096150.161296000.005
10417104170.0011104170.005
19.2k19.20k0.002
57.6k57.60k0.000
115.2k

Baud RateSYNC = 0, BRGH = 1, BRG16 = 0
FOSC = 32.000 MHzFOSC = 20.000 MHzFOSC = 18.432 MHzFOSC = 11.0592 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300
1200
2400
960096150.1620796150.1612996000.0011996000.0071
10417104170.00191104170.0011910378-0.37110104730.5365
19.2k19.23k0.1610319.23k0.166419.20k0.005919.20k0.0035
57.6k57.14k-0.793456.82k-1.362157.60k0.001957.60k0.0011
115.2k117.64k2.1216113.64k-1.3610115.2k0.009115.2k0.005

Baud RateSYNC = 0, BRGH = 1, BRG16 = 0
FOSC = 8.000 MHzFOSC = 4.000 MHzFOSC = 3.6864 MHzFOSC = 1.000 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
3003000.16207
120012020.1620712000.0019112020.1651
240024040.1620724040.1610324000.009524040.1625
960096150.165196150.162596000.0023
10417104170.0047104170.0023104730.5321104170.005
19.2k192310.162519.23k0.161219.2k0.0011
57.6k55556-3.55857.60k0.003
115.2k115.2k0.001

Baud RateSYNC = 0, BRGH = 0, BRG16 = 1
FOSC = 32.000 MHzFOSC = 20.000 MHzFOSC = 18.432 MHzFOSC = 11.0592 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300300.00.006666300.0-0.014166300.00.003839300.00.002303
12001200-0.0233321200-0.03104112000.0095912000.00575
24002401-0.048322399-0.0352024000.0047924000.00287
960096150.1620796150.1612996000.0011996000.0071
10417104170.00191104170.0011910378-0.37110104730.5365
19.2k19.23k0.1610319.23k0.166419.20k0.005919.20k0.0035
57.6k57.14k-0.793456.818-1.362157.60k0.001957.60k0.0011
115.2k117.6k2.1216113.636-1.3610115.2k0.009115.2k0.005

Baud RateSYNC = 0, BRGH = 0, BRG16 = 1
FOSC = 8.000 MHzFOSC = 4.000 MHzFOSC = 3.6864 MHzFOSC = 1.000 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300299.9-0.021666300.10.04832300.00.00767300.50.16207
12001199-0.0841612020.1620712000.0019112020.1651
240024040.1620724040.1610324000.009524040.1625
960096150.165196150.162596000.0023
10417104170.0047104170.0023104730.5321104170.005
19.2k19.23k0.162519.23k0.161219.20k0.0011
57.6k55556-3.55857.60k0.003
115.2k115.2k0.001

Baud RateSYNC = 0, BRGH = 1, BRG16 = 1 or SYNC = 1, BRG16 = 1
FOSC = 32.000 MHzFOSC = 20.000 MHzFOSC = 18.432 MHzFOSC = 11.0592 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300300.00.0026666300.00.0016665300.00.0015359300.00.009215
120012000.0066661200-0.01416612000.00383912000.002303
240024000.01333224000.02208224000.00191924000.001151
960096040.048329597-0.0352096000.0047996000.00287
10417104170.00767104170.00479104250.08441104330.16264
19.2k19.18k-0.0841619.23k0.1625919.20k0.0023919.20k0.00143
57.6k57.55k-0.0813857.47k-0.228657.60k0.007957.60k0.0047
115.2k115.9k0.6468116.3k0.9442115.2k0.0039115.2k0.0023

Baud RateSYNC = 0, BRGH = 1, BRG16 = 1 or SYNC = 1, BRG16 = 1
FOSC = 8.000 MHzFOSC = 4.000 MHzFOSC = 3.6864 MHzFOSC = 1.000 MHz
Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)Actual
 Rate%
ErrorSPBRG
 value
 (decimal)
300300.00.006666300.00.013332300.00.003071300.10.04832
12001200-0.02166612000.0483212000.0076712020.16207
240024010.0483223980.0841624000.0038324040.16103
960096150.1620796150.1610396000.009596150.1625
10417104170191104170.0095104730.5387104170.0023
19.2k19.23k0.1610319.23k0.165119.20k0.004719.23k0.1612
57.6k57.14k-0.793458.82k2.121657.60k0.0015
115.2k117.6k2.1216111.1k-3.558115.2k0.007