Information
PIC16(L)F1826/1827
DS80000485L-page 10 2009-2013 Microchip Technology Inc.
10.2 Auto-Baud Detect
When using automatic baud detection (ABDEN),
on occasion, an incorrect count value can be
stored at the end of 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 a 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”.
EXAMPLE 2: METHOD 1 – EUSART AUTO-BAUD DETECT WORK AROUND
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.
#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
•