I need some help here... I can't get this thing to work. I just started coding a I2C slave. Below is a bit of code that I wrote for detecting START & STOP conditions, as well as raising and falling CLK edges. The concept is simple. For every new sample form the PORTB I roll the bits of I2C_TRANS_REG (transition register) twice to the left and add SDA and CLK at the two LSBs. Obviously SCL is connected to PORTB[0], and SDA to PORTB[1] Then, after I mask-off the 4 MSBs I use the 4 LSBs to detect how the signals transitioned. However it doesn't work. The PIC runs at 10MHz and I am sure it is enough to keep up with the slow I2C master signals. I have been looking again and again in the code but can't see what is wrong. Can you spot anything? Also, I have commented out part of the code to simplify it as an attempt to debug it. I2C_BUS_SCAN rlf I2C_TRANS_REG, f rlf I2C_TRANS_REG, f movlw b'00001100' andwf I2C_TRANS_REG, f movf I2C_PORT, w ; Read I2C port... andlw b'00000011' ; and keep only CLK and DTA pins... iorwf I2C_TRANS_REG, f ; Then mix them with the old pin status sublw b'00001101' ; Check if DTA transitioned form 1 to 0 while CLK=1 btfsc STATUS, Z goto I2C_START_DETECT movf I2C_TRANS_REG, w ; Get a fresh copy of TRANS_REG sublw b'00000111' ; Check is DTA transitioned form 0 to 1 while CLK=1 btfsc STATUS, Z goto I2C_STOP_DETECT ; movf I2C_TRANS_REG, w ; Get a fresh copy of TRANS_REG ; andlw b'00000101' ; Keep only the old and new CLK bits ; sublw b'00000100' ; Check if CLK transitioned form 1 to 0 ; btfsc STATUS, Z ; goto I2C_CLK_FALL ; movf I2C_TRANS_REG, w ; Get a fresh copy of TRANS_REG ; andlw b'00000101' ; Keep only the old and new CLK bits ; sublw b'00000001' ; Check if CLK transitioned form 0 to 1 ; btfsc STATUS, Z ; goto I2C_CLK_RAISE goto I2C_BUS_SCAN -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body