PDA

View Full Version : 18LF4680 HSERIN and SEROUT hang my PIC!



temp19
- 18th May 2011, 18:22
The program are simply. To receive serially @ 115.2kbps data, and sometimes send serially (not hardware) data out.
initialization of hserin works well!

INCLUDE "bs2defs.bas"
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_CLOERR 1
DEFINE HSER_BAUD 115200

start:

hserin 100, start, [c, a, b]
rcsta.4 = 0 : rcsta.4 = 1

if c = "d" and a = "+" then sound portb.4, [119,7]
if c = "e" and a = ":" then hpwm 1, b, 400
if c = "s" then serout portc.4, t9600, [255, 8, 100]
goto start
------------------------------------------
everything work good and fine until c="s" and pic needs to transmit three bytes out of portc.4.
PIC just hangs up until reset :(

is something special about portC.4? am i missed something important?
18LF4680 hardware TR RX are C6 and C7

mister_e
- 18th May 2011, 22:55
smells of DMX project again ;)


DEFINE HSER_CLOERR 1

that one do absolutely nothing, the spelling is wrong

try these defines


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 10 ' 115200 Baud @ 20MHz, -1.36%
DEFINE HSER_CLROERR 1 ' Clear overflow automaticallyIf it's really DMX, you really need to study the protocol first, HSERIN will be of next to none use for that. There's a nice DMX paper on microchip website. I know I already posted it somewhere in here.

Another thing, you may want to use a BaudrateVouched crystal for this baudrate. 1.36% err is not bad though.

Archangel
- 19th May 2011, 02:02
Hi temp19,
2 things come to mind . . .
#1 I would set sspcon1.5 = 0 to disable spi and make an I/O. It may default to this on POR but I did not see it in the data sheet.
#2. Now I might be the only one who EVER had this trouble, but when making statements like :
if c = "d" and a = "+" then sound portb.4, [119,7]
it never works FOR ME without some brackets, like so
IF (c = "d") AND (a = "+") THEN sound portb.4, [119,7]
as I said it MAY work for everyone else, but not for me.