18F2520 HSEROUT baud rate oddity


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2005
    Posts
    15

    Default 18F2520 HSEROUT baud rate oddity

    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

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: 18F2520 HSEROUT baud rate oddity

    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.

    Code:
    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
    Last edited by Darrel Taylor; - 10th June 2013 at 20:32.
    DT

  3. #3
    Join Date
    Jan 2005
    Posts
    15


    Did you find this post helpful? Yes | No

    Default Re: 18F2520 HSEROUT baud rate oddity

    Thanks Darrel, really obvious now!
    I misread the data sheet. Thought it was capable of both types of USART.

    Thanks again!

Similar Threads

  1. How to change baud rate with HSEROUT?
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th November 2011, 02:48
  2. HSERIN HSEROUT - Baud rate help
    By George in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 15th September 2010, 08:05
  3. MCLoader baud rate
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th July 2010, 01:41
  4. Rf module baud rate
    By tazntex in forum Serial
    Replies: 4
    Last Post: - 5th August 2008, 18:47
  5. Baud Rate Converter
    By paul.mcallister in forum Serial
    Replies: 3
    Last Post: - 14th June 2008, 23:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts