Guides‎ > ‎

Auto Baud Rate Based on EUSART module

posted Dec 20, 2010, 6:49 PM by Danny Ng   [ updated Feb 8, 2011, 6:42 PM ]
The gadget you added is not valid

Most of the newer PIC come with the EUSART module which have the function for auto baud rate detection. The features allow a person to set the baud rate at runtime by sending the character "U" or 0x55 to the PIC. With ABDEN (auto baud rate enable) bit set and using BRG clock as a reference, each rising edge occurring on the RX pin is taken as a reference to calculate the SPBRG and SPBRGH value. After the Baud rate is set, the RCIF flag will be set. The receive register must be discarded as it doesn't contain meaningful data. The Image (PIC18F2455 datasheet, page 252) below shows the timing diagram for auto baud rate setup.

A circuit based similar to the UART test is used to demonstrate the capability of auto baud rate generation.Using the code in the project file attached, It will 1st wait for a character "U" to be send over for baud rate calculation. Auto baud is enable using the 3 lines of code below. The UARTReadByte() will read and discard the byte after a successful configuration of baud rate.

//AutoBaud Configuration
BAUDCONbits.WUE = 0;
BAUDCONbits.ABDEN = 1;
UARTReadByte(); // read to clear data

The LCD display will be the same as the image below after a successful program of the microcontroller. It is currently waiting for the character U to set the baud rate.
After receiving U, the LCD will display the value for SPBRGH:SPBRG. In the case of the example, 9600 baud is used and the output is 00CE.
It will send back the 2nd line of the LCD display back to the PC also.
The hex character are display and send to the PC based on the 2 codes below. The lower and upper nibble of the byte must be converted to ASCII code so that it can be displayed to the LCD and the PC.

char ConvertHex(char data){
switch(data){
case 0x0A:
return 'A';
case 0x0B:
return 'B';
case 0x0C:
return 'C';
case 0x0D:
return 'D';
case 0x0E:
return 'E';
case 0x0F:
return 'F';
default:
return (data |0x30);
}
}
void DisplayHex(char data){
char temp = data >> 4;
temp = ConvertHex(temp);
XLCDPut(temp);
    UARTSendByte(temp);  
temp = (data & 0x0F);
temp = ConvertHex(temp);
XLCDPut(temp);
    UARTSendByte(temp);  
}
Data can be sent through the serial port and displayed on the 2nd line of the LCD similar to the example of UART test. The final picture show the web address sent to the LCD.

ċ
EUSART.rar
(33k)
Danny Ng,
Dec 20, 2010, 7:37 PM
Comments