I2C Timeout Delay

Status
Not open for further replies.

Suraj143

Active Member
I'm using I2C module to communicate with DS1307.Somehow after 6 or 7 months continuously working in my clock now its giving some problems means sometimes the time is holding & never updates.When I restart power it works.

I added some timeout delay like nigel does.Please tell is that ok!!
Code:
I2C_Write	bsf	STATUS,RP0
		bcf	SSPCON2,RCEN		; Disable Recieve Mode
		bcf	STATUS,RP0	
		bcf	PIR1,SSPIF		; Clear Interrupt flag bit
		movwf	SSPBUF
		call	I2C_Wait_SSPIF
		bsf	STATUS,RP0
		clrf	count
WaitForACK	incf	count,F			; increase timeout counter each time ACK is not received
		btfsc	STATUS,Z
		return
		btfsc	SSPCON2,ACKSTAT		; Wait until Slave device
		goto	WaitForACK		; Acknowledge
		bcf	STATUS,RP0
		return

I2C_Wait_SSPIF	clrf	count
Wait_SSPIF	incf	count,F			; increase timeout counter each time SSPIF is not received
		btfsc	STATUS,Z
		return
		btfss	PIR1,SSPIF
		goto	Wait_SSPIF
		return
 
Last edited:
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…