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.
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
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!
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...
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..
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.
At the PC, type in a few characters (no hex codes, nothing crazy, just a few alpha or number characters), followed by the : character.Code: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
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.
Hi Skimask
Counter 0 to 7, perhaps? And possibly no quote marks in third line after 8?
Adrian
Bookmarks