PDA

View Full Version : How to set up UART??



jkbpower
- 23rd April 2007, 22:42
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

skimask
- 24th April 2007, 00:35
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?

mister_e
- 24th April 2007, 02:11
Get a copy of PicMulticalc, click on USART calc, enter your parameter, and you should have something like...


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...


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 :(

jkbpower
- 24th April 2007, 07:29
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

jkbpower
- 24th April 2007, 07:35
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

jkbpower
- 24th April 2007, 07:36
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

skimask
- 24th April 2007, 14:53
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

jkbpower
- 24th April 2007, 15:54
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.

jkbpower
- 25th April 2007, 08:09
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