View Full Version : 18f25k22 hserin
jackberg1
- 19th January 2025, 02:02
Hello,
I've tried to use the Hserin with no success, let me explain,
I used the example from the PBP3 compiler reference manual p:150
and scanning with hand barcode scanner nothing show or random character show up on the serial terminal.
the scanner is set at 9600,8,1,n and it's working on other application
I'm looking for the code to wait until I scan a code then it send to a serial port and come back waiting for the next scan.
is there someone who can help.
thanks to everyone
[/
'-------------------------------------------------------------------------
' Name : Hserin Test (18F25K22)
' Serout Baud rate: 188:4800,84:9600,49:14400,32:19200,15:28800,6:3840 0 'ok
' Serout : p296,297
' 9600 Open Inverted None 49236
' HSERIN [WAIT("!"), STR MyArray\200, STR MyArray(200)\200, _
' STR MyArray(400)\200, STR MyArray(600)\100]
'
'-------------------------------------------------------------------------
Include "modedefs.bas" ' Include serial modes
;----[18F25K22 Hardware Configuration]------------------------------------------
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = On
CONFIG WDTEN = Off
CONFIG MCLRE = INTMCLR
CONFIG LVP = Off
#ENDCONFIG
ANSELA = 0 ; All Digital
ANSELB = 0
ANSELC = 0
DEFINE OSC 64
TRISA = 111111 '1:IN, 0:OUT
TRISB = 111110
TRISC = 111111
OSCCON = $70
OSCTUNE = $40
' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
DEFINE HSER2_RCSTA 90h
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
DEFINE HSER2_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 9600
DEFINE HSER2_BAUD 9600
DEFINE HSER_CLROERR 1
AArray VAR BYTE[12]
BArray VAR BYTE[12]
' code to scan sample : 0 59749 96859 1
MAIN:
HSERIN [wait ("0"), str AArray\12]
serOut2 PORTB.0,84, [str BArray\12,13,10]
GoTo MAIN
rsocor01
- 19th January 2025, 02:51
I don't have the manual in front of me now, but I think that you are missing some parameters in the HSERIN command.
jackberg1
- 19th January 2025, 03:16
the manual is in PDF format.
Let me know what is missing when you can.
from the data sheet only 3 setup as to be done for receiving.
9897
thank you
rsocor01
- 19th January 2025, 04:06
Check this thread.
https://www.picbasic.co.uk/forum/showthread.php/17632-HSERIN-with-a-WAIT
rsocor01
- 19th January 2025, 04:24
Also, HSERIN starts saving the variables after the WAIT requirement has been met. In your case, it will only save 11 numbers instead of 12.
' code to scan sample : 0 59749 96859 1
MAIN:
HSERIN [wait ("0"), str AArray\11]
jackberg1
- 19th January 2025, 04:27
Thanks for your time, I'll look at it, also I did used a timeout label (hserin 5,MAIN,[STR AARRAY\12])
still no result.
Thanks again.
jackberg1
- 19th January 2025, 04:28
I rectified it (hserin 5,MAIN,[STR AARRAY\12])
jackberg1
- 19th January 2025, 04:34
here's the code from today post:
HSERIN [wait ("0"), str AArray\12]
serOut2 PORTB.0,84, [str BArray\12,13,10]
richard
- 19th January 2025, 04:50
Works ok for me if BArray has something printable placed in it
perhaps u wired it up incorrectly
jackberg1
- 19th January 2025, 13:20
Works ok for me if BArray has something printable placed in it
perhaps u wired it up incorrectly
even this
MAIN:
hserin 5,MAIN,[STR AARRAY\12]
serOut2 PORTB.0,84, [str aarray\12,13,10]
GoTo MAIN
amgen
- 19th January 2025, 14:30
....."0" is decimal 48
jackberg1
- 19th January 2025, 21:59
9898
....."0" is decimal 48
thanks to everyone involved to help me on this project.
I tried about every way to setup the HSerin1,2
still not working.
I'm realy suprise since these HSerin command are part of PBP3 for at least 15 years
and today in 2025 cannot find any reliable sample codes.
even the PBP3 examples does not work at all for my setup.
I had 1 rs232/ttl scanner bad (intermitent power on the rs232 rail)
connected another one and the only easy way to make work it's
with the code below.
MAIN:
'--------------------------------------------
serin2 PORTB.0,84,50,MAIN,[STR AARRAY\12]
serOut2 PORTB.1,84, [str aarray\12,13,10]
serOut2 PORTB.1,84, ["Done!",13,10]
'--------------------------------------------
GoTo MAIN
richard
- 19th January 2025, 23:46
works as expected
only slight change was to move serout to portb.7 to suit my pickit2 debug uart tool and put something printable
into BArray
'-------------------------------------------------------------------------' Name : Hserin Test (18F25K22)
' Serout Baud rate: 188:4800,84:9600,49:14400,32:19200,15:28800,6:3840 0 'ok
' Serout : p296,297
' 9600 Open Inverted None 49236
' HSERIN [WAIT("!"), STR MyArray\200, STR MyArray(200)\200, _
' STR MyArray(400)\200, STR MyArray(600)\100]
'
'-------------------------------------------------------------------------
Include "modedefs.bas" ' Include serial modes
;----[18F25K22 Hardware Configuration]------------------------------------------
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = On
CONFIG WDTEN = Off
CONFIG MCLRE = INTMCLR
CONFIG LVP = Off
#ENDCONFIG
ANSELA = 0 ; All Digital
ANSELB = 0
ANSELC = 0
DEFINE OSC 64
TRISA = % 11111111 '1:IN, 0:OUT
TRISB = % 11111111
TRISC = % 11111111
OSCCON = $70
OSCTUNE = $40
' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
DEFINE HSER2_RCSTA 90h
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
DEFINE HSER2_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 9600
DEFINE HSER2_BAUD 9600
DEFINE HSER_CLROERR 1
AArray VAR BYTE[12]
BArray VAR BYTE[12]
ARRAYWRITE BARRAY,["GOT IT",0]
' code to scan sample : 0 59749 96859 1
MAIN:
HSERIN [wait ("0"), str AArray\12]
serOut2 PORTB.7,84, [str BArray,13,10]
GoTo MAIN
what doesn't work are code snippets and failure to provide connection details [ schematic]
and even a description of what happens versus what you expect to happen
9899
richard
- 19th January 2025, 23:55
more useful would be
'-------------------------------------------------------------------------' Name : Hserin Test (18F25K22)
' Serout Baud rate: 188:4800,84:9600,49:14400,32:19200,15:28800,6:3840 0 'ok
' Serout : p296,297
' 9600 Open Inverted None 49236
' HSERIN [WAIT("!"), STR MyArray\200, STR MyArray(200)\200, _
' STR MyArray(400)\200, STR MyArray(600)\100]
'
'-------------------------------------------------------------------------
Include "modedefs.bas" ' Include serial modes
;----[18F25K22 Hardware Configuration]------------------------------------------
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = On
CONFIG WDTEN = Off
CONFIG MCLRE = INTMCLR
CONFIG LVP = Off
#ENDCONFIG
ANSELA = 0 ; All Digital
ANSELB = 0
ANSELC = 0
DEFINE OSC 64
TRISA = % 11111111 '1:IN, 0:OUT
TRISB = % 11111111
TRISC = % 11111111
OSCCON = $70
OSCTUNE = $40
' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
DEFINE HSER2_RCSTA 90h
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
DEFINE HSER2_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 9600
DEFINE HSER2_BAUD 9600
DEFINE HSER_CLROERR 1
AArray VAR BYTE[12]
BArray VAR BYTE[12]
ARRAYWRITE BARRAY,["GOT IT",0]
' code to scan sample : 0 59749 96859 1
MAIN:
HSERIN [wait ("0"), str AArray\12]
serOut2 PORTB.7,84, [str BArray,13,10]
hserout ["got", str AArray\12 ,13,10]
GoTo MAIN
9900
jackberg1
- 20th January 2025, 02:35
Hello everyone, and thank to all for helping me
this case is solved!
1st
the GM65 scanner Tx/Rx line are at 3.3v not at standard 5V TTL logic, so I add a BSS138 between the Tx and the Rx (HSerin) of the PIC
2nd
I like to thank also BrianS (HSERIN issue with a 18F452 and IF THEN statements or Case statements (https://www.picbasic.co.uk/forum/showthread.php/24234-HSERIN-issue-with-a-18F452-and-IF-THEN-statements-or-Case-statements))
while reading about his case I took part of the HSerin setup and added to my program, first try work just fine on HSerin/HSerin2.
'-------------------------------------------------------------------------
' Name : Hserin Test (18F25K22)
'-------------------------------------------------------------------------
Include "modedefs.bas" ' Include serial modes
;----[18F25K22 Hardware Configuration]------------------------------------------
#CONFIG
CONFIG FOSC = INTIO67
CONFIG PLLCFG = ON
CONFIG WDTEN = Off
CONFIG MCLRE = INTMCLR
CONFIG LVP = Off
#ENDCONFIG
'-------------------------
DEFINE HSER_CLROERR 1
DEFINE HSER_BAUD 9600
RCSTA = $90
TXSTA = $20
DEFINE HSER2_CLROERR 1
DEFINE HSER2_BAUD 9600
RCSTA2 = $90
TXSTA2 = $20
'-------------------------
ANSELA = 0 ; All Digital
ANSELB = 0
ANSELC = 0
DEFINE OSC 64
TRISA = 111101 '1:IN, 0:OUT
TRISB = 000001
TRISC = 111101
OSCCON = $70
OSCTUNE = $40
AArray VAR BYTE[12]
' code to scan sample : 0 59749 96859 1
MAIN:
HSERIN 50,MAIN,[STR AARRAY\12]
'HSERIN2 50,MAIN,[STR AARRAY\12]
' --------------------------------------------
serOut2 PORTB.1,84, [str aarray\12,13,10]
' --------------------------------------------
GoTo MAIN
9901
9902
9903
(https://www.picbasic.co.uk/forum/showthread.php/24234-HSERIN-issue-with-a-18F452-and-IF-THEN-statements-or-Case-statements)
jackberg1
- 20th January 2025, 02:36
Many thanks richard.
Take care.
richard
- 20th January 2025, 02:45
No code error , no compiler deficiency. as suggested in post #9 its wired incorrectly
who would have known
jackberg1
- 20th January 2025, 03:06
Specialy when the GM65 user manual mention TTL logic level, yes the DC supply is 5V, for the USB / UART ports.
but it's not specify 3.3V Tx/Rx output line.
Learning everyday like everyone here.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.