PDA

View Full Version : Hserout sends wrong values



picmilan
- 14th July 2016, 21:37
Hello again,
I have a working code for sending a byte using PIC18F24J50 but the same code doesn't send the correct values in PIC18F2450. I send $05 and receive 252 instead.

Here is my code:

DEFINE LOADER_USED 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200
DEFINE HSER_SPBRG 12
DEFINE HSER_CLOERR 1
DEFINE OSC 24

ADCON0 = 000000
ADCON1 = 001011
ADCON2 = 110101

TRISC.0 = 0
TRISC.1 = 1
TRISC.6 = 0
TRISC.7 = 1


tx1 VAR PORTC.6
rx1 VAR PORTC.7

LED VAR PORTC.0
Pause 1000

mainloop:

high LED
Pause 1000

Hserout [$05]
Pause 100

low LED
Pause 1000

Goto mainloop


Any ideas? Thanks!

picmilan
- 14th July 2016, 22:28
I also get 50 when I set HSER_TXSTA to 20h in low speed.

mackrackit
- 15th July 2016, 01:30
Are both chips running at the same speed?

richard
- 15th July 2016, 01:40
config is ?

picmilan
- 15th July 2016, 01:55
I am using standard config in P18F2450.INC file.


NOLIST
ifdef PM_USED
LIST
"Error: PM does not support this device. Use MPASM."
NOLIST
else
LIST
LIST p = 18F2450, r = dec, w = -311, w = -230, f = inhx32
INCLUDE "P18F2450.INC" ; MPASM Header
__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,_PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _BBSIZ_BB1K_4L & _XINST_OFF_4L
NOLIST
endif
LIST
EEPROM_START EQU 0F00000h
BLOCK_SIZE EQU 16




I basically trying to read the result using an arduino.


Here are sample of values I sent and values I get when I use Putty/Serial software :



Sent Received
0 1
1 2
2 12
3 14
4 48
5 50
6 60
7 62
8 192
9 194
10 204

richard
- 15th July 2016, 02:42
xtal used is ?

picmilan
- 15th July 2016, 03:34
xtal used is ?

It's a 24 mhz xtal.

richard
- 15th July 2016, 03:58
the default config is for a 20mhz xtal which gives a fosc of 48mhz

to use a 24 MHz xtal change plldiv to 6 for a 48mhz fosc or turn the pll off .
24 mhz into the pll @ plldiv5 is out of device specs.
with pll off and cpudiv=1 fosc=24mhz fo a 24mhz xtal.