I am having problem with I2C mode of 16f877a. I wrote a code for I2C ranging mode of the SRF02 sensors. At first I thought the problem was with the code, but then I debugged the circuit a little; the code is as below:
int main(){
TRISB = 0x00; //Port B is output
TRISD = 0x00; //Port D is output
//Get the range
while(1)
{
I2C_Init(2000000);
I2C_Start(void); // send start sequence
I2C_Wr(0xE0); // SRF02 I2C address with R/W bit clear
I2C_Wr(0x00); // SRF02 command register address
I2C_Wr(0x81); // command to start ranging in cm
I2C_Stop(void); // send stop sequence
delay_ms(70); //delay for 70ms.
I2C_Start(void); // send start sequence
I2C_Wr(0xE0); // SRF02 I2C address with R/W bit clear
I2C_Wr(0x02); // send internal adress of high byte.
I2C_Repeated_Start(void); // send a restart sequence
I2C_Wr(0xE1); // SRF02 I2C address with R/W bit set
PORTB=I2C_Rd(1); // get the high byte of the range and send acknowledge.
PORTC=I2C_Rd(0); // get low byte of the range - note we don't acknowledge the last byte.
I2C_Stop(void); // send stop sequence
}
return 0;
}
This code would normally first of all make a PIC generate a clock on the CLK pin of the PIC (I think this is what I2C_Init() command does). But I observed on Scope that there is no clock on this pin. I only observed 5V dc. I heard that 16f877a PICs have problems with i2c, and now I observe that it simply does not generate clock.
PS: I also wrote MIKROC's example simple code to the PIC to eliminate my mistakes, just to check the presence of the clock. Still, I could not see it. My final conclusion is: 16f877a does not generate clock in I2C mode.=> no i2c operation is possible?
Does anyone has similar problem? Should I change the Microcontroller?