accole32
Posts: 4
Joined: Tue Jan 15, 2013 11:49 am

5V i2c device problems

Tue Jan 15, 2013 12:05 pm

Hi,

I'm trying to get multiple i2c devices talking to the RPi and at least one is a 5V i2c device (a servo controller - SD20, based on a PIC micro controller).

I have set up a level shifter similar to the circuit on http://playground.arduino.cc/Main/I2CBi ... velShifter (but using 2N7000 MOSFETs) and whilst I can communicate with the 3.3V devices just fine, I cannot communicate with the 5V device (sudo i2cdetect -y 0 only reports the 3.3v devices). The only difference I am aware of is the SD20 communicates at 400KHz whereas the other devices run at 100KHz... do I have to add special coding to talk at the higher speed (I haven't found any mention of how to!)

I've used as close to the 1.8KR pullups the RPi has on the 5V side (no pullups on the 3.3V side as RPi has those).

Any ideas what I might be doing wrong?

Thanks,
Anthony

Peter247
Posts: 56
Joined: Wed Nov 21, 2012 12:29 am

Re: 5V i2c device problems

Tue Jan 15, 2013 1:50 pm

The speed the rate the bus is set at , not the top speed of each chip.

You are not saying if you are using python or c++ and which labrary you are using.
If you are using python i2cdev the default speed is 100k.
http://www.peter224722.blogspot.co.uk/

accole32
Posts: 4
Joined: Tue Jan 15, 2013 11:49 am

Re: 5V i2c device problems

Tue Jan 15, 2013 2:08 pm

Hi Peter,

I'm using the smbus python library for my software, but the i2cdetect command (which is just part of the i2c-tools) doesn't spot the 400kHz device. Looking at code I have from when I used this device with a PICAXE controller I had to use 400kHz comms to get the device to work. Is there an easy way to change the RPi to use 400kHz comms ?

Thanks,
Anthony

Peter247
Posts: 56
Joined: Wed Nov 21, 2012 12:29 am

Re: 5V i2c device problems

Tue Jan 15, 2013 2:55 pm

I think a tmp102 is capable of 400k , but does not have to run at that rate .
I`ve knocked mine down to 40k , to see if it would work with my adc at 40k.

make a file " /etc/modprobe.d/i2c.conf "
and use:-

options i2c_bcm2708 baudrate=400000

and Reboot !!!! and now you should have 400k
http://www.peter224722.blogspot.co.uk/

accole32
Posts: 4
Joined: Tue Jan 15, 2013 11:49 am

Re: 5V i2c device problems

Wed Jan 16, 2013 1:55 pm

Thanks Peter. I will try this when I can (at work today!).

I wonder if there is a way thr RPi can switch between the two comms rates without rebooting? (I am assuming that at least one of my devices wont work at 400kHz)

A

User avatar
joan
Posts: 14179
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: 5V i2c device problems

Wed Jan 16, 2013 2:39 pm

You should be able to rmmod the module and then modprobe it again with the new values. Shouldn't require reboot.

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: 5V i2c device problems

Wed Jan 16, 2013 3:45 pm

accole32 wrote:Hi,

I'm trying to get multiple i2c devices talking to the RPi and at least one is a 5V i2c device (a servo controller - SD20, based on a PIC micro controller).

I have set up a level shifter similar to the circuit on http://playground.arduino.cc/Main/I2CBi ... velShifter (but using 2N7000 MOSFETs) and whilst I can communicate with the 3.3V devices just fine, I cannot communicate with the 5V device (sudo i2cdetect -y 0 only reports the 3.3v devices). The only difference I am aware of is the SD20 communicates at 400KHz whereas the other devices run at 100KHz... do I have to add special coding to talk at the higher speed (I haven't found any mention of how to!)

I've used as close to the 1.8KR pullups the RPi has on the 5V side (no pullups on the 3.3V side as RPi has those).

Any ideas what I might be doing wrong?
Two ideas:

1. Too much pull-up. By having 1.8K pull-ups on both sides of the NFETs, the combined resistance is 0.9K. I2C pull-down transistors may be weak (the spec only requires 3 mA) so your 5V I2C device may not be able to pull down far enough. The Arduino circuit shows 10K pull-ups on both sides, which combine to 5K which is easily pulled down by 3 mA. Try using 10K on the 5V side. That gives you a combined 1.5K pull-up, which is only slightly more than 3 mA would like to pull down from 5V.

2. The 2N7000 MOSFET has a higher Vgs threshold than the BSS138 recommended by the Arduino note. The higher Vgs threshold means that the transistor will have a harder time turning on.

If you have an Oscilloscope, check the waveforms and see if the SDA/SCL are going low enough on both sides.

pgman
Posts: 22
Joined: Sun Jan 06, 2013 8:34 pm

Re: 5V i2c device problems

Sat Jan 19, 2013 12:47 am

Remove the pullup resistors on the 5v side, and ditch the convertors.

I've used a 5v DS1307 clock just fine on 3.3v I2C rail. This was achieved by only having pullup resistors on the 3v3 side, ie the built in ones on the Raspberry.

According to I2C specs the logic levels for 3v3 I2C are within the tolerances of 5v I2C, and you only need one set of resistors across the entire I2C bus, as long as its not too long (> 2m). Very long runs may be different.

Also read some docs on how having too large a resistance on I2C bus causes it to slow down by creating too much rise time for each pulse. The 1k8 resistors on the Pi are just right for 3v3.

accole32
Posts: 4
Joined: Tue Jan 15, 2013 11:49 am

Re: 5V i2c device problems

Thu Jan 24, 2013 9:51 pm

With everything I have read I decided that just leaving without any protection would perhaps not be wise (thanks anyway pgman). So, I removed the mosfets and pullups leaving just the RPi pullups, but put zener diodes to get rid of any excess voltage on sda/scl and that seems to have worked.. I can now communicate with the SD20 (without even having to force the RPi to 400KHz) so I think that is a good result - thanks for all the advice chaps.

Onwards... :)
A

Return to “Interfacing (DSI, CSI, I2C, etc.)”