PDA

View Full Version : hserout not working with parity



Pic2008
- 23rd March 2010, 15:35
'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?

ScaleRobotics
- 23rd March 2010, 16:06
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

Pic2008
- 23rd March 2010, 23:38
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?

Darrel Taylor
- 24th March 2010, 02:29
I remember this problem.
Took me awhile to find it again ...

http://www.picbasic.co.uk/forum/showpost.php?p=41572&postcount=2

hth,

Pic2008
- 24th March 2010, 06:45
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?

Darrel Taylor
- 24th March 2010, 08:39
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 ...
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 ...
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,

Pic2008
- 24th March 2010, 13:25
Ok, thanks Darrel. It works now.