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 Trouble (sspcon2 Problem)

Status
Not open for further replies.

jay543_uk

New Member
HI ALL, IV BEEN TRYING TO USE I2C ON A PIC 16F876A AND I CARNT GET IT TO WORK.
IV NARROWED THE PROBLEM DOWN USING A PICKIT2 BUT CARNT WORK IT OUT.
THE PROBLEM IS THAT AFTER I RUN THIS PIECE OF CODE AND IT GETS TO"BSF SSPCON2,SEN" THE SSPCON2 STILL READS 0x00 ie THE I2C START CONDITION ISNT BEING CARRIED OUT FOR SOME REASON CAN ANY1 HELP ME PLEASE........
HERES MY CODE
Code:
InitI2C: ; The subroutine of I2C Initialization 
BANKSEL TRISC
movlw B'00011000' ; Initial PortC,bit 3 & 4 as Input
movwf TRISC ; RC3 = SCL , RC4 = SDA

BANKSEL PORTC
movlw 0xff
movwf PORTC

movlw .100 ; This gives 100KHz I2C clock @ 4MHz
banksel SSPADD
movwf SSPADD
movlw b'10000000' ; Disable slew rate control.
banksel SSPSTAT
movwf SSPSTAT
movlw b'00000000' ;
movwf SSPCON2 ; Setup MSSP for continuous reception.
movlw b'00101000' ; Enable MSSP and setup for I2C master
banksel SSPCON ; mode.
movwf SSPCON
banksel	PIR1
movlw	0x00
movwf	PIR1
return


I2CWAIT
	banksel PIR1
FLoop btfss PIR1,SSPIF
	goto	FLoop
	bcf PIR1,SSPIF
return

I2CSTART
	BANKSEL	SSPCON2
	BSF		SSPCON2,SEN
	CALL	I2CWAIT
	BANKSEL	0
	RETURN

THANKS FOR ANY HELP

JASON
 
Looks like you have SSPADD on the slow side for now, which is fine. For some reason my code has the SSPSTAT.CKE bit set for the SMP bus, and it has worked for a variety of devices, might try that.

You don't say what your slave is... if its another Pic, then try clock stretching on that side. Getting another Pic to ACK back (i.e. same problem as yours), proved a real hassle for me.

Only thing else is to double check your slave address and pullups for the clock and data lines. Also solid grounds, SCK and SDA line connections are important.
 
i am trying to use a 16f876a as a master and a ds1337 rtc as a slave, i seem to have all my pullup resistors in plase. if any of the circuit was wrong wouldnt the sspcon2 register still show 0x01 as iv bsf the sen (0,bit)of it.
 
Can't see anything wrong with your code, so the questions about the hardware. Have you tried the CKE bit for kicks? Also see that I clear the SSPIF flag prior to setting SEN, could be an unnecessary artifact. Is the SCL or SDA line being held low?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top