PDA

View Full Version : HSEROUT with 18F2420 won't work



flotulopex
- 16th October 2016, 11:33
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?

' 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

HenrikOlsson
- 16th October 2016, 12:33
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.

flotulopex
- 16th October 2016, 12:47
There' only ONE word to say: Wow!!!

Thanks a lot Henrik :smile: