1.6.1 Auto-Baud Detect May Store Incorrect Count Value in the SPBRG Registers

When using automatic baud detection (ABDEN), on occasion, an incorrect count value can be stored at the end of the auto-baud detection in the SPBRGH:SPBRGL (SPBRG) registers. The SPBRG value may be off by several counts. This condition happens sporadically when the device clock frequency drifts to a frequency where the SPBRG value oscillates between two different values. The issue is present regardless of the baud rate Configuration bit settings.

Work around

When using auto-baud, it is good practice to always verify the obtained value of SPBRG, to ensure it remains within the application specifications. Two recommended methods are shown below.

For additional auto-baud information, see Technical Brief TB3069, "Use of Auto-Baud for Reception of LIN Serial Communications Devices: Mid-Range and Enhanced Mid-Range".

Method 1 - EUSART Auto-Baud Detect Work Around

#define SPBRG_16BIT  *((*int) &SPBRG; // Define location for 16-bit SPBRG value
const int DEFAULT_BAUD = 0x0067;          // Default Auto-Baud value
const int TOL = 0x05;                     // Baud Rate % tolerance
const int MIN_BAUD = DEFAULT_BAUD - TOL;  // Minimum Auto-Baud limit
const int MAX_BAUD = DEFAULT_BAUD + TOL;  // Maximum Auto-Baud limit

ABDEN = 1;                                 // Start Auto-Baud
while(ABDEN);                              // Wait until Auto-Baud completes
if((SPBRG_16BIT > MAX_BAUD) || (SPBRG_16BIT < MIN_BAUD))
{                                        // Compare if value is within limits
    SPBRG_16BIT = DEFAULT_BAUD;          // If out of spec, use DEFAULT_BAUD
}                                        // If in spec, continue using the
                                         // Auto-Baud value in SPBRG
Note: In firmware, define default, minimum, and maximum auto-baud (SPBRG) values according to the application requirements. For example, if the application runs at 9600 baud at 16 MHz, then the default SPBRG value would be (assuming 16-bit Asynchronous mode) 0x67. The minimum and maximum allowed values can be calculated based on the application. In this example, a ±5% tolerance is required, so tolerance is 0x67 * 5% = 0x05.

Method 2 - EUSART Auto-Baud Detect Work Around

#define SPBRG_16BIT  *((*int)&SPBRG; // Define location for 16-bit SPBRG value
const int DEFAULT_BAUD = 0x0067;         // Default Auto-Baud value
const int TOL = 0x05;                    // Baud rate % tolerance
const int MIN_BAUD = DEFAULT_BAUD - TOL; // Minimum Auto-Baud limit
const int MAX_BAUD = DEFAULT_BAUD + TOL; // Maximum Auto-Baud limit
int Average_Baud;                      // Define Average_Baud variable
int Integrator;                        // Define Integrator variable
Average_Baud = DEFAULT_BAUD;           // Set initial average baud rate
Integrator = DEFAULT_BAUD * 15;        // The running 16 count average

ABDEN = 1;                             // Start Auto-Baud
while(ABDEN);                          // Wait until Auto-Baud completes

Integrator+ = SPGRB_16BIT;
Average_Baud = Integrator/16;
if((SPBRG_16BIT > MAX_BAUD) || (SPBRG_16BIT < MIN_BAUD))
{                                     // Check if value is within limits
    SPBRG_16BIT = Average_Baud;       // If out of spec, use previous average
}
else                                  // If in spec, calculate the running
{                                     // average but continue using the
    Integrator+ = SPBRG_16BIT;        // Auto-Baud value in SPBRG
    Average_Baud = Integrator/16;
    Integrator- = Average_Baud;
} 
Note: Similar to Method 1, define default, minimum, and maximum auto-baud (SPBRG) values. In firmware, compute a running average of SPBRG. If the new SPBRG value falls outside the minimum or maximum limits, then use the current running average. For example, if the application runs at 9600 baud at 16 MHz, then the default SPBRG value would be (assuming 16-bit Asynchronous mode) 0x67. The minimum and maximum allowed values can be calculated based on the application. In this example, a ±5% tolerance is required, so tolerance is 0x67 * 5% = 0x05.

Affected Silicon Revisions

A1 A2 A3
X X