How to set up UART??


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Posts
    10

    Default How to set up UART??

    Hi,
    I´m trying to set upp the harware serial port to send ASCII to a serial LCD display.
    I´m using a 18F6585 running at 10MHz.

    Can anyone help with the setup?
    I have tried the following:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 19200
    DEFINE OSC 10

    I use a MAX232 as a RS232 driver.
    When I connect the pic to a PC and use HyperTerm I can get something out from the pic but it look like garbage.
    Almost as the pic is transmitting at wrong speed.
    /JKBPower

  2. #2
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by jkbpower View Post
    Hi,
    I´m trying to set upp the harware serial port to send ASCII to a serial LCD display.
    I´m using a 18F6585 running at 10MHz.

    Can anyone help with the setup?
    I have tried the following:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 19200
    DEFINE OSC 10

    I use a MAX232 as a RS232 driver.
    When I connect the pic to a PC and use HyperTerm I can get something out from the pic but it look like garbage.
    Almost as the pic is transmitting at wrong speed.
    /JKBPower
    Your code looks a bit iffy...Are you sure it's running at 10mhz?

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    Get a copy of PicMulticalc, click on USART calc, enter your parameter, and you should have something like...
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 32  ' 19200 Baud @ 10MHz, -1.36%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    If that device have an EUSART, you can also use...
    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 129 ' 19200 Baud @ 10MHz, 0.16%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    Error % is better.


    NOW, you have to show us your configuration fuse setting.

    PICMultiCalc available bellow...
    http://www.mister-e.org/pages/utilitiespag.html

    Configuration Fuses setup and how to..
    http://www.picbasic.co.uk/forum/showthread.php?t=543

    Maybe your PIC is running @10MHZ... but you you didn't set the right Fuses. That one have a few to set first
    Last edited by mister_e; - 24th April 2007 at 01:13.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Apr 2007
    Posts
    10

    Default

    Thanks guys.

    First I just have to say that this PicMultiCalc is the BEST :-).

    I setup the fuse in programmer software but I am going to put it in my program instead.
    Now I have a 10Mhz crystal.
    OSC=HS, PWRT=ON, BOR=OFF, WDT=OFF, LVP=OFF, DEBUG=OFF

    I still can´t get anything out from the serial port.
    /JKBPower

  5. #5
    Join Date
    Apr 2007
    Posts
    10

    Default

    This is what my 18F6585.INC file look like!

    ;************************************************* ***************
    ;* 18F6585.INC *
    ;* *
    ;* By : Leonard Zerman, Jeff Schmoyer *
    ;* Notice : Copyright (c) 2003 microEngineering Labs, Inc. *
    ;* All Rights Reserved *
    ;* Date : 06/19/03 *
    ;* Version : 2.44 *
    ;* Notes : *
    ;************************************************* ***************
    NOLIST
    ifdef PM_USED
    LIST
    "Error: PM does not support this device. Use MPASM."
    NOLIST
    else
    LIST
    LIST p = 18F6585, r = dec, w = -302, f = inhx32
    INCLUDE "P18F6585.INC" ; MPASM Header
    ; __CONFIG _CONFIG1H, _OSC_XT_1H
    ; __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_128_2H
    ; __CONFIG _CONFIG4L, _LVP_OFF_4L
    __CONFIG _CONFIG1H, _OSCS_OFF_1H & _OSC_HSPLL_1H
    __CONFIG _CONFIG2L, _PWRT_ON_2L
    __CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_128_2H
    __CONFIG _CONFIG4L, _LVP_OFF_4L & _STVR_OFF_4L & _DEBUG_OFF_4L
    __CONFIG _CONFIG5H, _CPD_OFF_5H
    __CONFIG _CONFIG6H, _WRTD_OFF_6H
    NOLIST
    endif
    LIST
    EEPROM_START EQU 0F00000h
    BLOCK_SIZE EQU 8

  6. #6
    Join Date
    Apr 2007
    Posts
    10

    Default

    I forgot to say that I dont run the pic at 10Mhz as I said erlier.
    I use HSPLL function and run it at 40MHz.
    /JKBPower

  7. #7
    skimask's Avatar
    skimask Guest

    Default

    Quote Originally Posted by jkbpower View Post
    I forgot to say that I dont run the pic at 10Mhz as I said erlier.
    I use HSPLL function and run it at 40MHz.
    /JKBPower
    Then you have to DEFINE OSC 40 'cause it's running at 40Mhz, not 10Mhz

  8. #8
    Join Date
    Apr 2007
    Posts
    10

    Default

    Yes, I use OSC 40.
    But still not working as it should.
    Maybe I have something wrong in my design with the MAX232 curcuit.
    I will do a check to if it works.

  9. #9
    Join Date
    Apr 2007
    Posts
    10

    Default

    Hi again,
    hmm.. its a little embarrassing.
    I´ve got it working now.
    I just had to shift the RX and TX line on the RS232 cable. hehe.
    I took the scope and saw that both my pic and the PC tried sending data on same line.
    But I got lot of help from you anyway. Like this PicMultiCalc software :-)
    /JKBPower

Similar Threads

  1. Pin won't stay high during Repeat...Until loop??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th August 2009, 23:57
  2. Interruptus Frustratus
    By Byte_Butcher in forum General
    Replies: 16
    Last Post: - 17th April 2009, 20:36
  3. 16F628A - Stops if release power switch.
    By dene12 in forum General
    Replies: 16
    Last Post: - 14th February 2009, 07:57
  4. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  5. error on compiling
    By parker in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 16th June 2005, 14:31

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