PDA

View Full Version : How do I format HSERIN?



PlantBob
- 1st July 2008, 23:52
I am using a 16f688 and I use HSEROUT with no problems. I now need to send some data back to the 16f688. How do I format the HSERIN command if I don't know how much data is coming?

Thanks,
Bob Hiller
Lifts for the Disabled LLC

skimask
- 2nd July 2008, 00:52
I am using a 16f688 and I use HSEROUT with no problems. I now need to send some data back to the 16f688. How do I format the HSERIN command if I don't know how much data is coming?
HSEROUT has provisions for an 'ending' character. You can fill an array of bytes up to said 'end' character. See HSEROUT in the PBP manual. Look at the STR modifier.

PlantBob
- 2nd July 2008, 03:24
I see no reference to filling an array and waiting for termination characters in the PBP manual. Do you have a sample?

Thanks,
Bob Hiller
Lifts for the Disabled LLC

Darrel Taylor
- 2nd July 2008, 03:41
I think he meant ...

See HSERIN in the PBP manual. Look at the STR modifier.
<br>

n7hri
- 2nd July 2008, 12:30
Being a beginner myself I have the same problem with getting simple commands and mondifiers to function. I'm looking in the PBP manual at the STR Modifier and they just don't give any examples on how to use it. I'm also interested in the use of this function as I would like to be able to send commands to the PIC and dinamicly update it.

skimask
- 2nd July 2008, 13:42
I think he meant ...
See HSERIN in the PBP manual. Look at the STR modifier.
<br>
Yep, that's what I meant...
der.....:)

Bruce
- 2nd July 2008, 15:20
MyVars VAR BYTE(8)

Main:
HSERIN 500,NoData,[STR MyVars\8\"~"]

NoData:
do something else

This will wait 500mS before jumping to NoData. It will receive a string of up to 8 characters
in byte array MyVars, or exit on receipt of the "~" character.

PlantBob
- 2nd July 2008, 17:40
From a PC I send 123:CRLF as 495051581310

When I try:
MyVars VAR BYTE(8)

Main:
HSERIN 500,NoData,[STR MyVars\6\":"]

goto main

NoData:
HSEROUT ["Timeout",$0d,$0a]
Goto main

It always goes to NoData. I never get anything into MyVars.

If I use HSERIN 500,NoData,[STR MyVars\1\":"] I get random data. It is different each time I send the data.

What am I missing?

Thanks,
Bob Hiller
Lifts for the Disabled LLC

Bruce
- 2nd July 2008, 17:52
Have you tried increasing the timeout period?

P.S. How do you know what you're receiving? Your example doesn't show how you're
checking what's received!

skimask
- 2nd July 2008, 17:56
Don't send 123:CRLF as 495051581310....send it as 123:<CR> with line feeds turned on at the PC.
HSERIN doesn't need to use raw hex codes for the data (i.e. sending 10 for a line feed, etc).

Are you using the internal oscillator on the PIC?
The internal oscillator isn't always accurate. Could cause your baud rate to be off by just enough to confuse everything.

Are you using a MAX232 type device between the PIC and the PC?
The hardware UART uses 'TTL-RS232', commonly called 'Normal' in PBP circles. Try using SERIN2/SEROUT2 and using an inverted mode if you don't have a MAX232.

Are you sure the PIC is configured correctly for the desired baud rate?
Can get a bit confusing with all of the options a PIC has. Double check them...

Are you sure the config registers/any other registers are set up correctly?
Internal vs. External crystals...and so on and so on...

PlantBob
- 2nd July 2008, 18:19
I am using MAX32 between the PC and PIC.

HSEROUT works every time no matter what I send. Thank makes me assume that the BAUD issue is OK.

Here is how I check what I am receiving:

HSEROUT ["B1 ", MyVars(0), $0d,$0a]
HSEROUT ["B2 ", MyVars(1), $0d,$0a]
HSEROUT ["B3 ", MyVars(2), $0d,$0a]
HSEROUT ["B4 ", MyVars(3), $0d,$0a]
HSEROUT ["B5 ", MyVars(4), $0d,$0a]

etc..

skimask
- 2nd July 2008, 19:16
I am using MAX32 between the PC and PIC.
HSEROUT works every time no matter what I send. Thank makes me assume that the BAUD issue is OK.
Ok, just checking, didn't have that info before.
Like I said before, don't send the raw hex data back and forth, just send the characters themselves.


MyVars VAR BYTE[8] : temp var byte
Main: HSERIN 5000,NoData,[STR MyVars\6\":"]
HSEROUT ["Received:", STR myvars\8",13,10] : goto main
NoData: HSEROUT ["Timeout",$0d,$0a]
for temp = 0 to 8 : myvars[temp]=0 : next temp 'clean out myvars
Goto main

At the PC, type in a few characters (no hex codes, nothing crazy, just a few alpha or number characters), followed by the : character.
The code above should wait for 5 seconds to 1)get no data, 2) get 6 bytes of data, or 3)will kick out and send back the data you just sent if you sent a : before you sent a total of 6 bytes.

Adrian
- 8th July 2008, 16:34
Hi Skimask

Counter 0 to 7, perhaps? And possibly no quote marks in third line after 8?

Adrian

skimask
- 8th July 2008, 19:29
Hi Skimask
Counter 0 to 7, perhaps? And possibly no quote marks in third line after 8?
Adrian

Quote marks - yes...
Counter 0 to 7 - perfectly valid.
MyVars var Byte[8] sets aside 9 bytes, index 0 (zero) is also valid.

Adrian
- 8th July 2008, 21:16
Hi Skimask
Thanks but there is something I'm not understanding. I've tried your programme and it works fine until the first timeout then it won't 'goto main' and loop through again. Should it? If I change the counter to FOR temp = 0 to 7 then the programme loops round endlessly. What am I not understanding or what am I doing wrong? Please help - going mad here!!

Adrian

skimask
- 9th July 2008, 16:04
Might get a couple of hints from this:
http://www.picbasic.co.uk/forum/showthread.php?t=4681&highlight=hserin+idle

If not there, then try a search on serial and idle and see what happens.

BobP
- 9th July 2008, 20:33
Hi,

I usually refer back to this sample program if I forget how to use a modifier;

http://www.melabs.com/resources/samples.htm

and load the sample program ser2mod.bas

Bob

Adrian
- 9th July 2008, 22:31
Thanks for that Bob. The bit I was confused about is Skimask's statement "MyVars var Byte[8] sets aside 9 bytes, index 0 (zero) is also valid"
I thought I understood that MyVars VAR BYTE[8] had 8 elements numbered 0 to 7 (Page 26 PBP new manual). If that were the case then the 'clearance' counter ought surely to be 0 to 7 not 0 to 8, which would be invalid.

Adrian

skimask
- 10th July 2008, 13:37
Thanks for that Bob. The bit I was confused about is Skimask's statement "MyVars var Byte[8] sets aside 9 bytes, index 0 (zero) is also valid"
I thought I understood that MyVars VAR BYTE[8] had 8 elements numbered 0 to 7 (Page 26 PBP new manual). If that were the case then the 'clearance' counter ought surely to be 0 to 7 not 0 to 8, which would be invalid.
Adrian
Ya know...you're right. I've been reading that line in the manual 'bass-ackward' all this time. Never had a problem with it, but still.........

Adrian
- 10th July 2008, 22:54
Thank you for that, Skimask. I really appreciate you coming back and putting this one to bed once and for all. I guess that Counter 0 to 7 clears the temp array and 0 to 8 hangs up due to the extra 'rogue' index.
I really do appreciate your input and have learned some more about this interesting and all absorbing science

Regards & thanks

Adrian