I'm using Receive Character (RCIF) interrupts along with a circular buffer and checking for "overrun" and "framing" errors in my interrupt handler.
My question is, if I get an "overrun" or a "framing" error, will that prevent the USART from generating an RCIF interrupt? In other words, is there a chance that an error can occur but I won't know about it because the USART didn't generate an RCIF interrupt and the error conditions are only being checked in my interrupt handler?
Honestly, I don't think I've ever experienced either type of USART error condition in the past but I'd like to make my code more robust so I'd like to include error handling capability. I'm just not sure how to do it.
TIA... Cheerful regards, Mike
My question is, if I get an "overrun" or a "framing" error, will that prevent the USART from generating an RCIF interrupt? In other words, is there a chance that an error can occur but I won't know about it because the USART didn't generate an RCIF interrupt and the error conditions are only being checked in my interrupt handler?
Honestly, I don't think I've ever experienced either type of USART error condition in the past but I'd like to make my code more robust so I'd like to include error handling capability. I'm just not sure how to do it.
TIA... Cheerful regards, Mike
Code:
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; interrupt vector ~
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
org 0x0004
v_int ; using 'RCIF' interrupts only
;
; check for 'framing' and 'overrun' error conditions
;
movlb RCSTA/128 ; bank 3 |03
btfsc RCSTA,FERR ; framing error? no, skip, else |03
bra FERR_error ; branch (correct framing error) |03
btfsc RCSTA,OERR ; overrun error? no, skip, else |03
bra OERR_error ; branch (correct overrun error) |03
;
; prep for indirect access at 'push' pointer in circular buffer
;
movlw rxbuf/256 ; FSR1 = &rxbuf[push] |03
movwf FSR1H ; " |03
movlw rxbuf%256 ; " |03
addwf push,W ; " |03
movwf FSR1L ; " |03
;
; add Rx character to circular buffer (clears RCIF int flag)
;
movf RCREG,W ; get Rx char, clear RCIF flag |03
movwf INDF1 ; rxbuf[push] = rcreg |03
;
; if push pointer + 1 equals pull pointer, exit (buffer full)
;
incf push,W ; |03
andlw buffersize-1 ; wreg = ++push % buffersize |03
xorwf pull,W ; full (push + 1 == pull)? |03
skpnz ; no, skip, else |03
retfie ; exit (ignore new character) |??
;
; increment 'push' pointer
;
xorwf pull,W ; wreg = ++push % buffersize |03
movwf push ; update 'push' pointer |03
retfie ; |??
;
; handle 'overrun' and 'framing' errors ????
;
OERR_error
FERR_error
bcf RCSTA,SPEN ; reset receiver |03
movf RCREG,W ; clear RCReg |03
movf RCREG,W ; |03
bsf RCSTA,SPEN ; enable receiver |03
retfie ; |??
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Last edited: