PDA

View Full Version : Problem with HSEROUT/HSERIN



financecatalyst
- 26th June 2013, 15:05
I have this code:

Gain:
HSERIN [STR Name\25\"*"] : Pause 250
HSEROUT [STR Name,"*"]
for pass=0 to 24
Name[pass]=0
next pass
Goto Gain

First time when program starts. I can see on serial communicator when data 'Home*' is received. Nothing comes as output

I send it again 'Home*' it outputs 0

Third time I send 'Home*' it outputs 'Home*'

THEN I send 'abcd*' it outputs 'Home*'

I send it again 'abcd*' it outputs 'abcd*'

Similarly every different data after this comes to the output after sending it twice.

Why is this happening?

HenrikOlsson
- 26th June 2013, 15:30
Hi,
Have you declared Name as an array of 25 bytes?

Name VAR BYTE[25]

/Henrik.

financecatalyst
- 26th June 2013, 15:37
Yes. Variables are able to hold the value.

HenrikOlsson
- 26th June 2013, 16:33
Hi,
Then I don't know...
That can't be all of the code can it? Try to reduce the code to the bare minimum which still shows the issue, then post that code.

I've tried the following on a 18F25K20 running at 64MHz

DEFINE OSC 64
DEFINE LOADER_USED 1 ' We're using a bootloader.
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 138 ' 115200 Baud @ 64MHz, -0,08%

SPBRGH = 0
BAUDCON.3 = 1 ' Enable 16 bit baudrate generator

Name VAR BYTE[25]
pass var byte

Pause 200

HSEROUT["Program start.",13]

Gain:
HSERIN [STR Name\25\"*"] : Pause 250
HSEROUT [STR Name,"*"]
for pass=0 to 24
Name[pass]=0
next pass

Goto Gain

It seems to work fine using the serial communicator terminal built into MicroCodeStudio...


/Henrik.

financecatalyst
- 26th June 2013, 17:12
Here is the code, the problem is there:

'-----------------Defines & Includes----------------
Include "modedefs.bas"
DEFINE OSC 20

'------------------------Configuration Fuses-------------
#CONFIG
ifdef PM_USED
device pic16F877A, xt_osc, wdt_on, lvp_off, protect_off
else
__CONFIG _HS_OSC & _WDT_OFF & _LVP_OFF & _CPD_ON & _CP_ALL & _PWRTE_ON & _BODEN_ON
endif
#ENDCONFIG


@ ERRORLEVEL -306 ' SUPRESS PAGE BOUNDRY ERROR

'===================================
DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 64 ' 19200 Baud @ 20MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

'======================================
'--------------------REGISTERS-------------------------------
PAUSE 100
ADCON1=7 ' No Analog
CMCON=7
OPTION_REG=128
TRISA=0 : PORTA=0
TRISB=0 : PORTB=0 ' Enter Button Input
TRISC=%10000000 : PORTC=0 ' One pin to get data
TRISD=%10000000 : PORTD=0
TRISE=0 : PORTE=0
CCP1CON=0

Name Var Byte[25]
Pass Var Byte
'--------------------------------------------------------------

Name=0 : Pass=0

Gain:
HSERIN [STR Name\25\"*"] : Pause 250
HSEROUT [STR Name,"*"]
For pass=0 to 24
Name[pass]=0
next pass
Goto Gain

wdmagic
- 3rd July 2013, 09:43
I have found im having the same problem, but I think Ive found a fix, you can tinker with it more. the program does not like the reset to 0 loop, also the name VAR make it 1 more than what you want so make it a 26, also put the loop first before doing serin/out and maybe add a pause 100 inside the loop. Im going to post my code for 8 bytes, its working great so far, i removed the loop and set each one seperately, it helped get rid of bad serial character loss/corruption dont know why though.


include "LCD_D.BAS"
Define OSC 20 'USE ECIO, NOT ECPIO
define HSER_BAUD 2400
DEFINE HSER_BITS 8
DEFINE HSER_CLROERR 1
RCSTA = $90
TXSTA = $20 'DO NOT USE $24
TRISC = %10000000
TRISD = 0

Name Var Byte[8]

Gain:
Name[0] = 0
Name[1] = 0
Name[2] = 0
Name[3] = 0
Name[4] = 0
Name[5] = 0
Name[6] = 0
Name[7] = 0
Name[8] = 0
HSERIN 5000,test,[STR Name\8] : Pause 250
HSEROUT [STR Name, 13, 10]
LCDOUT $FE, 2
LCDOUT $FE, $80
LCDOUT Name[0],Name[1],Name[2],Name[3],Name[4],Name[5],Name[6],Name[7]
pause 250
Goto Gain

test:
pause 100
goto gain

Hope this helps or gives ideas!