Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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.

Latest threads

New Articles From Microcontroller Tips

Back
Top