PDA

View Full Version : pic18f4520 baud rate change to 115200



caltex88
- 29th September 2007, 17:00
hi guys....

right now the default is 19200...using a 4MHZ osscilator. i need 115200 baud rate for my gsm modem...rumour that i need got to change to a 20Mhz osscilator...but can i change it into 16Mhz?


and what do i've to change in the code as well

penUSART (USART_TX_INT_OFF & // Transmit interrupt ON/OFF
USART_RX_INT_ON & // Receive interrupt ON/OFF
USART_ASYNCH_MODE & // ASYNCH/SYNCH MODE
USART_EIGHT_BIT & // Transmission Width
USART_CONT_RX &
USART_BRGH_HIGH,8);


is the code right for 115200 baud rate...


thanks in advance

Charles Linquis
- 29th September 2007, 21:20
115Kbaud with a 4MHz XTAL is tough. Because the divisor has to be an integer, you can get only within 3.55% of the exact baud rate. That error is probably a bit too much. Look at the datasheet table 18-3.

20Mhz works much better. That gives you a 1.36% error. Small enough to work well.
In this case, set BRGH = 1 and SPBRG = 10

caltex88
- 30th September 2007, 07:46
115Kbaud with a 4MHz XTAL is tough. Because the divisor has to be an integer, you can get only within 3.55% of the exact baud rate. That error is probably a bit too much. Look at the datasheet table 18-3.

20Mhz works much better. That gives you a 1.36% error. Small enough to work well.
In this case, set BRGH = 1 and SPBRG = 10

what about 16Mhz XTAL

mister_e
- 30th September 2007, 08:41
With 16 MHz the best error Percentage you'll get will be -0.79% witch is usually fair enough.

This assume you're aware that you MUST use the 16 bit baudrate generator for that.

Now to set it in C... it's your problem ;) In PicBasic Pro


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_SPBRG 34 ' 115200 Baud @ 16MHz, -0.79%
SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator


My PicMultiCalc should help you a little bit
http://www.mister-e.org/pages/utilitiespag.html