Hi,
Is this ok?
C
[Moderator: Added code tags, highlighted lines (9, 29, 49, 51, and 57)
Is this ok?
C
[Moderator: Added code tags, highlighted lines (9, 29, 49, 51, and 57)
Code:
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
'ADD second line¦
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
robi(robipsn) = RXIRQchar 'store $
robi_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 robi_fill = 1 Then 'if filling buffer, see if there is room in buf
If robipsn >= (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
robipsn = robipsn + 1 'else, there's room in buf so bump index and store character, might be W
robi(robipsn) = RXIRQchar
If RXIRQchar = "W" Then 'if end of sentence..
RCSTA.CREN = 0 'shut down UART
PIE1.RCIE = 0
robi_fill_state = 1 'flag buf full
Goto RXIRQdone 'and bye!
Endif 'RXIRQchar was W
Endif 'if robi_fill = 1
Endif 'RCIF=1
Endif 'RCIE=1
'Exit point for each RXinterrupt. Process timers
RXIRQdone:
Last edited by a moderator: