| Re : PIC16F876 en I2C
Bonjour,
Si tu fais cela, et que tu reçois un Nack, tu vas boucler indéfiniment.
Personnellement, j'ai repris les routines présentes dans le pdf. A savoir :
BANKSEL SSPCON2
btfsc SSPCON2,ACKSTAT ; Check ACK Status bit to see if I2C
goto I2CFail ; failed, skipped if successful
; Send and Check the STOP condition, wait for it to complete
BANKSEL SSPCON2
bsf SSPCON2,PEN ; Send STOP condition
call WaitMSSP ; Wait for I2C operation to complete
bcf STATUS, RP1
bcf STATUS, RP0
return
; *** SUBROUTINES & ERROR HANDLERS ***
; I2C Operation Failed code sequence - This will normally not happen,
; but if it does, a STOP is sent and the entire code is tried again.
I2CFail
BANKSEL SSPCON2
bsf SSPCON2,PEN ; Send STOP condition
call WaitMSSP ; Wait for I2C operation to complete
bcf STATUS, RP0
bcf STATUS, RP1
return
; This routine waits for the last I2C operation to complete.
; It does this by polling the SSPIF flag in PIR1.
WaitMSSP
BANKSEL PIR1 ; BANK 0
btfss PIR1,SSPIF ; Check if done with I2C operation
goto $-1 ; I2C module is not ready yet
bcf PIR1,SSPIF ; I2C module is ready, clear flag.
return
|