The problem is that if you're getting OERRs then you are loosing bytes. Why not setup an IRQ and a fifo buffer to prevent overflow errors? If you need code for a fifo then let me know.
The problem is that if you're getting OERRs then you are loosing bytes. Why not setup an IRQ and a fifo buffer to prevent overflow errors? If you need code for a fifo then let me know.
Here you go, add the variables to your variable, add an interrupt and put the first bit of code.
To use it, just call GetFifo and if the Zero flag is set then W has the received byte.
Note, FifoLength must be a either 16,32,64 etc.
Code:
FifoLength equ 10h
cblock 020h ;must be on 16 byte boundary
FifoBuffer:FifoLength ;16 byte input buffer
FifoStart
FifoEnd
endc
;code for in ISR
;no test for fifo full.
btfss PIR1,RCIF ;cleared automatically
goto NoReceive1
movfw FifoEnd
addlw low(FifoBuffer)
movwf FSR ;indirect addr
movfw RCREG
movwf INDF
movfw FifoEnd
addlw 1
andlw FifoLength-1 ;make wrap
movwf FifoEnd
NoReceive ;rest of ISR
;check if byte available
;returns with zero flag set if empty
;else has value in W
GetFifo
movfw FifoStart
subwf FifoEnd,W
btfsc STATUS,Z
return ;zero flag set
movfw FifoStart
addlw low(FifoBuffer)
movwf FSR
movfw FifoStart
addlw 1
andlw FifoLength-1
movwf FifoStart
movfw INDF
bcf STATUS,Z
return
Yes, that is a fifo buffer located at 0x50 and going to 0x6f. The variable S_FSR is the equivalent of my FifoEnd variable. There will have to be additional code to check and remove bytes from the buffer.
I just did a 16F887 processor PIC 2 PIC- RS232, 1 wire , TX - Rx protocol to move 32 digital channels (GPIO) over the RS232 to 'mirror' on the rcvr.
Well, asynchronous RS232 leads to data loss due to non sync'd processor clocks, so I included a check sum to reject bad data. The stock transfer averaged around 75% good data. Usable but it bugged me.
So, I created a slow s'ware PLL to correct and get a 100% data rate. Basically I set the recvr OSCTUNE setpoint a little fast and then used the cumulative data error rate to slowly correct downward until a stable 100% data rate was 'locked' in.
The phase lock takes about 30 seconds as it has to be done slowly to not 'miss' the correct tune point as i didn't want to do a whole PID code for the job. About 12 asm instructions overall.
You can detect baud rate by measuring the duration of the data bits, then adjust OSCTUNE accordingly. If you can receive a known character such as 0x55 then it's really easy. Otherwise, it'll take a number of characters to figure out.