Hi,
I am trying to test SRF02 ultrasonic rangers I just bought and to do that I connected them as required, and wrote a program in MIKROC for I2C transmission. My problem is that everytime I power up the curcuit my PIC burns. I connected pull up resistors to each of SDA and SCL lines; could it be that these resistors impose too much current into SCL and SDA pins of the PIC? Maybe I have to use a buffer between bus and 5V? The code is below. I am new to embedded programming so any of your comments would be of much use to me.
Thank you,
Denis
The Code:
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;
}