On High Interrupt
Save System
'OVERRUN ERROR
If PIE1.RCIE = 1 Then 'EUSART Receive Interrupt Enable bit
If RCSTA.OERR = 1 Then
Gosub irqinitbuf 're-init buffer, discard bad sentence
Goto RXIRQdone 'done, wait for next character
Endif 'OERR
'FRAMING ERROR
If RCSTA.FERR = 1 Then
dumpchar = RCREG 'Read char to clear RCIF and FERR
Gosub irqinitbuf 'Re-init buffer, discard bad sentence
Goto RXIRQdone 'wait for next
Endif 'FERR
'No UART errors, process character
If PIR1.RCIF = 1 Then
RXIRQchar = RCREG 'read the received char, clears RCIF
'Look for $, start/restart filling buf when found
If RXIRQchar = "$" Then 'Start (re)filling buf on any $
Gosub irqinitbuf 'init buffer, index and flags@
gnrmc_buf(gnrmcpsn) = RXIRQchar 'store $ $ ADDED instead of RXIRQchar, because no $ was being stored
gnrmc_buf_filling = 1 'start storing the sentence
Goto RXIRQdone 'done with this character
Endif 'char was $
'no UART errors and character was not $
'If $ was found previously, process character looking for W and no buffer overflow.
'If haven't found $ yet, just ignore character.
If gnrmc_buf_filling = 1 Then 'if filling buffer, see if there is room in buf
Break '<<<<<<<<<<<,
If gnrmcpsn >= (rxbufsize - 1) Then 'last char was at end of buf - buffer overflow so..
Gosub irqinitbuf 'restart buffer, discard sentence
RXerr = 1 'let main know that the buffer overflowed and is restarting
Goto RXIRQdone 'done, resume looking for next $
Endif 'buffer overflow
gnrmcpsn = gnrmcpsn + 1 'else, there's room in buf so bump index and store character, might be W
gnrmc_buf(gnrmcpsn) = RXIRQchar
If RXIRQchar = "W" Then 'if end of sentence..
RCSTA.CREN = 0 'shut down UART
PIE1.RCIE = 0 'Enable off
gnrmc_buf_filling = 0
gnrmc_buf_full = 1
Goto RXIRQdone 'and bye!
Endif 'RXIRQchar was W
Endif 'If gnrmc_buf_filling = 1
Endif 'RCIF=1
Endif 'RCIE=1
'Exit point for each RXinterrupt. Process timers
RXIRQdone:
Resume