;setup serial port
MOVLB 4 ;SPI controls in Bank4 |B4
CLRF SSPSTAT ;CKE=0, SMP=0 (sample at middle) |B4
MOVLW b'00100000' ;
MOVWF SSPCON1 ;CKP=0,master clk =Fosc/x (see below),
;SPEN <5> enabled
;04.25.15 tried all 3 settings for <3,0>, Fosc/64 did not work, others did,
;hung up on waiting for the BF flag bit. 0001=Fosc/16 should work wtih
;all Fosc up to 32 MHz. 0000=Fosc/4. AS5048 internal clock is ca. 5 MHz. ˜˜
GetSPI
MOVLB 2 ; |B2
BCF CSn ;!CS |B2
MOVLB 4 ; |B4
MOVLW 0xFF ;alternative to zeros |B4 |B4
MOVWF SSPBUF ; |B4
; CLRF SSPBUF ;initiates duplex communication |B4
GetBUFF
;NB:Polling SSPSTAT,BF seems to work as well as polling PIR1,SSPIF and
;doesn't require bank switching.
btfss SSPSTAT,BF
goto $-1
movf SSPBUF,w
movwf SPI_H
CLRF SSPBUF
btfss SSPSTAT,BF
goto $-1
movf SSPBUF,w
movwf SPI_L
movlb 2 ; |B2
bsf CSn ;set !SS(CSn)high |B2
; movlb 4 |B4
; BCF SSPCON1,SSPEN ;disable SPI port leave running |B4
ErrTest
BTFSC SPI_H,6 ;checks error bit and returns if set
GOTO Test0
BCF SPI_H,7 ;clears parity bit so print not effected 08.01.15
BSF SPI_H,7
;SET BIT<7> TO FLAG HIGH (MSB) BYTE WHEN SENDING EUSART TO STEPPER
;insert save data steps here
nop
; DelayCy (150*msecs)
; DelayCy (150*msecs)
call RegPrnt
goto GetSPI