HSEROUT with 18F2420 won't work


Closed Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938

    Default HSEROUT with 18F2420 won't work

    Hi,

    I'm trying to use HSEROUT instead of SEROUT/SEROUT2 with my 18F2420.

    As the code below works with SEROUT2, I only get garbage characters while using HSEROUT.

    I use a 4MHz crystal, defines come from Mister E's calculator, settings are for 2400bps, ...

    What am I missing/doing wrong please?
    Code:
    ' HSEROUT_18F2420.pbp
    
    ' ====== FUSES =====================================================================================
    @ __CONFIG _CONFIG1H, _OSC_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H ;_OSC_INTIO7_1H
    @ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOREN_OFF_2L & _BORV_0_2L
    @ __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H
    @ __CONFIG _CONFIG3H, _MCLRE_OFF_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_PORTBE_3H
    @ __CONFIG _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    @ __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
    @ __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
    @ __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
    @ __CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
    @ __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
    @ __CONFIG _CONFIG7H, _EBTRB_OFF_7H & _DEVID1 & _IDLOC0
    
    ' ====== DEFINES ===================================================================================
    DEFINE OSC 4
    
    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 160 ' 2400 Baud @ 4MHz, -0.08%
    SPBRGH = 1
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    
    ' ====== PROGRAM ===================================================================================
    MAIN:
    
        HSEROUT ["Hello",13,10]
        'Serout2 PORTC.6,16780,["Hello",13,10] ' 2400bps DIN
    
        PAUSE 1000
    
        GOTO MAIN
    
    ' ====== CIRCUITRY =================================================================================
    'PORTA.0[02]
    'PORTA.1[03]
    'PORTA.2[04]
    'PORTA.3[05]
    'PORTA.4[06]
    'PORTA.5[07]
    'PORTA.6[10] OSC2 - Xtal
    'PORTA.7[09] OSC1 - Xtal
    
    'PORTB.0[21]
    'PORTB.1[22]
    'PORTB.2[23]
    'PORTB.3[24]
    'PORTB.4[25]
    'PORTB.5[26]
    'PORTB.6[27] ICSP
    'PORTB.7[28] ICSP
    
    'PORTC.0[11]
    'PORTC.1[12]
    'PORTC.2[13]
    'PORTC.3[14]
    'PORTC.4[15]
    'PORTC.5[16]
    'PORTC.6[17] TX
    'PORTC.7[18] RX
    
    'PORTE.3[01] MCLR
    Roger

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: HSEROUT with 18F2420 won't work

    Hi,
    Using 16780 as the MODE means that the data is being sent inverted. The USART on the other hand sends the data true (non inverted), that's the reason it doesn't work for you.
    Some chips can invert the UART output and it looks like you're in luck with the 18F2420, try adding BAUDCON.4=1 to your code.

    /Henrik.

  3. #3
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Thumbs up Re: HSEROUT with 18F2420 won't work

    There' only ONE word to say: Wow!!!

    Thanks a lot Henrik
    Roger

Similar Threads

  1. Math problem that won't work
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th August 2012, 23:59
  2. Why LCD won't work with RS connected to PortA.6 of 18F452?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 8th April 2012, 00:55
  3. My PIC program won't work! Plz Help?!
    By beckyzammi in forum mel PIC BASIC
    Replies: 2
    Last Post: - 4th March 2010, 18:26
  4. Replies: 3
    Last Post: - 28th October 2009, 05:18
  5. Basic Compiler won't work with Vista
    By AMay in forum mel PIC BASIC
    Replies: 4
    Last Post: - 7th June 2008, 10:04

Members who have read this thread : 0

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