PDA

View Full Version : 18F2520 HSEROUT baud rate oddity



iphillipsca
- 10th June 2013, 19:35
Hello all, been looking around and haven't found an answer for this issue. That being said, it's usually something I'm missing...

I was using an 18F252(worked fine) and migrating to an 18F2520. The device outputs data to an LCD using HSEROUT.

The configs have been adjusted and it seems to work. The only thing is when the HSER_BAUD is set to 9600(or any other) my monitor(a debug serial program on PC) it is running at 38400(or twice the set rate) consistantly and reliably.
Here is the config I have and the serial setup.

DEFINE OSC 32
; 18F2520 CONFIG
#CONFIG
__CONFIG _CONFIG1H, _OSC_INTIO67_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
__CONFIG _CONFIG2H, _WDT_OFF_2H
__CONFIG _CONFIG3H, _CCP2MX_PORTC_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L
#ENDCONFIG

OSCCON= %01110000 'set internal osc to 8mhz
OSCTUNE=%01000000 'turn on PLL for the 32mhz


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_CLROERR 1 ' Clear overflow automatically
DEFINE HSER_BAUD 9600
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

I am also using Mr. Taylor's interrupts(thanks!). Not sure if they are messing with the timings or not.
I figured that the Timers would be different from the Internal OSC by the diagrams on the data sheet.
Like I said, it seems to work but just at the wrong baud.

Thanks.

Ian

Darrel Taylor
- 10th June 2013, 20:26
PBP's DEFINE HSER_BAUD is for setting up the baud rate of a USART.
The compiler has no way of knowing when you set BRG16 (BAUDCON.3) in your code for EUSART 16-bit baudrate mode.

For 16-bit mode, you must set the baud rate values manually.


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 64 ' 9600 Baud @ 32MHz, 0.04%
SPBRGH = 3
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

iphillipsca
- 10th June 2013, 21:01
Thanks Darrel, really obvious now!
I misread the data sheet. Thought it was capable of both types of USART.

Thanks again!