Hi E,hi C,
You could check for a character in the serial buffer, by using an ASM statement, prior to trying HSERIN.
E
Hi E,hi C,
As your serial inputs are not synchronised, recall what we had to do sometime ago.
If the RX buffer gets buffer gets data and it is not Read, then the OERR flag is set, if you do not test for this flag, when you read the buffer it could be 'old' rubbish data.
We used the following routine.
get_neo:
If RCSTA.OERR = 1 Then 'if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1
char = RCREG
char = RCREG
PIR1.RCIF = 0
Endif
sync1: 'wait for a $ start of string
If PIR1.RCIF = 0 Then Goto sync1
char = RCREG
If char <> 0x24 Then Goto sync1 '$'
str1(1) = char
rxi = 2
------------------------------------------------------------------------------------
get_data:
'Await GPS RXD -----------------GPS RMC ----------------------
''''''PASTE: $GNRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A?
'''OR PASTE: $REMOTE,1100,1200,1300,1400,1500,1600,?
If RCSTA.OERR = 1 Then 'if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1 'ENABLES RECEIVER
char = RCREG
char = RCREG 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Hserout "RX Err!", CrLf
Goto skip1
Endif
'Hserin char
'HSERGET TEST
Hserget char
If char = "$" Then 'start
str1(0) = char
str2(0) = char
rxi = 1
Else
Goto skip1
Endif
nxt_rxin:
Hserin char
If char = "?" Or char = 0x0a Then Goto msg_eol
str1(rxi) = char 'Set to only use str1 or 2
str2(rxi) = char
'Hserout str1(rxi) 'show for testing only
rxi = rxi + 1
Goto nxt_rxin
'Hserout CrLf
msg_eol: 'Sends received and saved message via HSEROUT
strtim = ""
strlat = ""
strlat = ""
strlong = ""
strtp = ""
strpr = ""
msg1 = ""
------------------------------------------------------------------------------------------------------
Do you program in C? If you do, you can do assembly. Simply code the hex and jump to it.Hi E,
I can't 'do' ASM, and as I'm tidying up, I'll leave this till later in my project.
Thanks.
C.
Hi B,Where's your flowchart. Do you understand how to actually manage trains of data, and parsing, or are you still at the spaghetti code stage?
Hi E,hi C,
When a OERR is flagged I have found it wise to do a double RX Bfr read.
Look at this link
https://www.microchip.com/forums/m1035054.aspx
Most datasheets advise to toggle CREN and to read RCREG a couple of times.
Hi E,hi C,
You are Exiting a GOTO call to subroutine with a RETURN.
Its the Program thats hanging not the UART
E
get_data:
If RCSTA.OERR = 1 Then 'if over run error then flush RXD buffer
RCSTA.CREN = 0
RCSTA.CREN = 1 'ENABLES RECEIVER
char = RCREG '1
char = RCREG '2
PIR1.RCIF = 0 'clear the RCIF flag, which had been set by the earlier err data.
Hserout "RX Err!", CrLf
Goto skip1 ' ?????????????????????????????????
Endif
......................................................................
skip1:
For x = 0 To 79
str1(x) = 0
Next x
For x = 0 To 79
str2(x) = 0
Next x
Return '???????????????????????????????
by Duane Benson
by Aaron Carman
by Duane Benson