Success!!!
I tested the following code on a recently purchased PIC18F2525, which I do believe is a newer revision level then the earlier problem parts that Microchip reported.
I tried it repeatably at baud rates spanning from 300 to 115,200 Baud with no apparent problems. Each and every time the baud rate was properly detected and set by sending a single ascii "U" character (uppercase).Code:'******************************************* ' EUSART Auto Baud Rate Detection ' PIC18F2525/2620/4525/4620 ' Author: Michael St. Pierre ' Date: 10/30/2005 '******************************************* DEFINE OSC 40 '============================================ ' Equates '============================================ rxdata VAR byte ' temporary storage for received data RCIF VAR PIR1.5 ' EUSART receive interrupt flag ABDEN VAR BAUDCON.0 ' Auto-Baud Detect Enable bit '============================================ ' Set-up EUSART for Auto-Baud detection '============================================ ' Note: The BRG clock source needs to be set for the optimum ' match at all anticipated incoming baud rates (we are optimized ' for a 40Mhz clock source and can detect from 300 to 115,200 Baud). TXSTA = %00100100 ' Transmit enabled ' BRGH set = 1 for High Baud enable RCSTA = %10010000 ' Receive enabled BAUDCON = %00001001 ' Auto-Baud Detect enabled ' BRG16 set = 1 for 16 Bit BRG counter '============================================ ' Program Start '============================================ ' The EUSART's built-in Auto-Baud Detect function waits to receive ' a single ascii "U" character as the synchronizing event. Once ' received and processed, the SPBRG and SPBRGH registers will be ' automatically set for the best possible baud rate match. While ABDEN = 1: Wend ' loop until Auto-Baud Detect is cleared... rxdata = RCREG ' then clear RCIF (discard "U" character) mainloop: While RCIF = 0: Wend ' loop until data present in EUSART buffer... rxdata = RCREG ' then retrieve data, TXREG = rxdata ' and send it! Goto mainloop ' Get next character
It's not only nice having the Auto-Baud Detect as a built-in hardware function, but also very sweet to have a 16 bit BRG counter. This allows for a much wider range of usable baud rates as compared to the normal 8 bit version in the standard USART's.
I'm definately sold on this one!




Bookmarks