Let's Make Robots!

SRF02 and 16f877a in I2C mode ranging

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;
}
 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
TeleFox's picture
Yep, there's nothing in the above circuit that would lead to such a problem, so there must be an issue with a short circuit/bad connection, or one of the parts is broken.

I tried to draw the connection diagramm I used. Below is the exact circuit I used(all connections shown). I did not quite understand what "I2C protocol libriary" means, but I used I2C rules described in this page:

http://www.robot-electronics.co.uk/acatalog/using_the_i2c_bus.htm

By the way, I am implementing my circuit on the breadboard(I thought maybe bad connection might be caused by the breadboard) 

Connection_diagramm_1.jpg 

TeleFox's picture

Well, at worst those resistor will draw less than 3mA with the circuit operating off a 5V supply, so no problems there. 50mA should not be enough to totally wreck a PIC, unless you've fried the drivers for one of the programming pins - which ones are you using for the I2C bus? The SRF02's should draw ~4mA each, and the PIC should draw <15mA, are there any other devices currently connected to the PIC or power supply?

I suspect that there is a problem with either the design or physical implementation of this circuit, would you be able to supply a circuit diagram and a copy of your I2C protocol library?

TeleFox's picture

Firstly, what do you mean when you say your PIC burns? Secondly, what value are the pull-up resistors?

by PIC burns I mean that when the ranging begins I observe high current (about 50mA) from the power supply. And after, when I am trying to reprogram it I can't do it as the programmator no longer recognises the PIC. The values of resistors are 1.8K each.