Hi,
I have CODE that reads RX IN DATA and PARSES it into sections, for use later.
Because of other clashes, I want to try SERIN instead.
Is this a completely different CODE or can I slip the SERIN into where the RX IN was for PARSING.
As I don't know the term for the RX IN CODE, I've posted a section:
Gereral answers please, just so I know which way to look.
Cheers, Camerart
I have CODE that reads RX IN DATA and PARSES it into sections, for use later.
Because of other clashes, I want to try SERIN instead.
Is this a completely different CODE or can I slip the SERIN into where the RX IN was for PARSING.
As I don't know the term for the RX IN CODE, I've posted a section:
Gereral answers please, just so I know which way to look.
Cheers, Camerart
Code:
On High Interrupt
Save System
If PIE1.RCIE = 1 Then
'overrun error
If RCSTA.OERR = 1 Then
RCSTA.CREN = 0 'disable UART
RXIRQchar = RCREG '1 'clear UART RX registers
RXIRQchar = RCREG '2
RCSTA.CREN = 1 'reenable UART
Gosub IRQinitBuf 're-init buffer, discard bad sentence
Goto RXIRQdone 'done, wait for next character
Endif 'OERR
'framing error
If RCSTA.FERR = 1 Then
RXIRQchar = 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
buf(rxpsn) = RXIRQchar 'store $
buf_fill = 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 buf_fill = 1 Then 'if filling buffer, see if there is room in buf
If rxpsn >= (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
rxpsn = rxpsn + 1 'else, there's room in buf so bump index and store character, might be W
buf(rxpsn) = RXIRQchar
If RXIRQchar = "W" Then 'if end of sentence..
RCSTA.CREN = 0 'shut down UART
PIE1.RCIE = 0
buf_done = 1 'flag buf full
Goto RXIRQdone 'and bye!
Endif 'RXIRQchar was W
Endif 'if buf_fill = 1
Endif 'RCIF=1
Endif 'RCIE=1
'Exit point for each RXinterrupt. Process timers
RXIRQdone: