hserout not working with parity


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2008
    Posts
    66

    Question hserout not working with parity

    Code:
    'PIC18F4550
     __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    	
           
    __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            
    __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    __CONFIG    _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H 
     __CONFIG    _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    
    
    DEFINE OSC 48      
    
    
    BAUDCON.3 = 1 'SETUP FOR HIGH SPEED.
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 24H 'HIGH SPEED MODE BAUD RATE GENERATOR
    DEFINE HSER_BAUD 38400
    DEFINE HSER_SPBRG 38H '38400 BAUD =56 dec
    DEFINE HSER_SPBRGH 01H
    
    
    HSEROUT ["HELLO",13,10] 'test

    The above code works, but when i added the following, it gives out garbage character in hyperterm 38400,E,8,1

    DEFINE HSER_EVEN 1
    DEFINE HSER_BITS 9

    Any idea?
    Last edited by Pic2008; - 23rd March 2010 at 16:41.

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    When I use Mister E's Pic Multi Calc, it gives me these settings for hser at that baud rate:

    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 77 ' 38400 Baud @ 48MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically

  3. #3
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Default

    Correct since you are using BRG16=0. Note that mine is BRG16=1.

    But my problem is not the bps, it is the parity. It all works fine without parity.

    Anyone else can help?

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


    Did you find this post helpful? Yes | No

    Default

    I remember this problem.
    Took me awhile to find it again ...

    http://www.picbasic.co.uk/forum/show...72&postcount=2

    hth,
    DT

  5. #5
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Question

    Hi Darrel,
    i already use

    DEFINE HSER_EVEN 1
    DEFINE HSER_BITS 9


    but in hyperterminal it shows garbage. I set hyperterminal to 8 data bit, even parity, 1 stop bit.

    If i dont use the above 2 defines and set hyperterminal to 8data bit, no parity, 1 stop bit, no problem.

    Is this a bug with PIC18f4550?

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


    Did you find this post helpful? Yes | No

    Default

    What I was trying to say in the other thread was ...

    If you want 9 total bits (8 data + 1 parity) then the USART must be set for 9-bit operations.
    That is done by setting TX9 (TXSTA.6) and RX9 (RCSTA.6) bits.

    With your current settings, that would be ...

    DEFINE HSER_RCSTA 0D0h
    DEFINE HSER_TXSTA 64h


    However, PBP will do that for you, if you let it.
    But when you use these defines ...
    Code:
    DEFINE HSER_RCSTA 90H
    DEFINE HSER_TXSTA 24H 'HIGH SPEED MODE BAUD RATE GENERATOR
    then you have specified what TXSTA and RCSTA values should be, and that overrides anything PBP will do.
    And 9-bit will not be enabled.

    If you don't define TXSTA and RCSTA, then PBP will do it for you, and all you have to tell it is the baud rate, total bits and parity.
    In your case ...
    Code:
    DEFINE OSC 48 ; set oscilator speed to 48mHz 
    DEFINE HSER_BAUD  38400
    DEFINE HSER_BITS 9
    DEFINE HSER_EVEN 1
    DEFINE HSER_CLROERR 1 ; Clear overflow automatically
    hth,
    Last edited by Darrel Taylor; - 24th March 2010 at 09:41.
    DT

  7. #7
    Join Date
    Aug 2008
    Posts
    66


    Did you find this post helpful? Yes | No

    Thumbs up

    Ok, thanks Darrel. It works now.

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