3
\$\begingroup\$

Ok, I understand similar questions have been asked in the past, please bear with me. Here is my problem, I have 2 I2C devices to be connected to a single I2C bus. They happen to be the same component and have the same hardware address. The address cannot be changed. My application requires the minimum possible latency. My plan is to use MOSFETs on the SDA line so that I can control when each of those devices is active. For each device there will be a MOSFET and by switching that on and off, I should be able to enable and disable them.

Would this work? If not, what would?

UPDATE: Ok, so I got my hands on MOSFETs (IRF520). I hooked up a digital pin on my arduino to the gate and the SDA lines to the source and drain (Arduino end to drain and device end to source). The thing didnt seem to be working, it gave me wrong values and would just stop entirely on bigger values. So I decreased the I2C frequency to 100kHz from 400kHz and it worked. I know the problem is in the FET because it works fine at 400kHz when the sensor is connected directly. Trouble is, I need it to work at 400kHz. What causes this issue and how can I rectify it? I was considering switching to the IRL540, would this help?

My messy diagram is as follows (I plan to repeat it for each sensor): enter image description here

\$\endgroup\$
  • \$\begingroup\$ What is this device? A lot of devices have I2C/SPI capabilities and if this one does, that would be great... \$\endgroup\$ – Matt Young Sep 29 '13 at 15:04
  • \$\begingroup\$ Perhaps a CMOS analog multiplexer is all you need. \$\endgroup\$ – Dave Tweed Sep 29 '13 at 15:08
  • \$\begingroup\$ @Matt This is an ultrasonic sensor I found while working on a school project. It has absolutely no documentation whatsoever. I ran an I2C scanner to find its address and I highly doubt its got SPI, largely because it doesnt even have a datasheet. \$\endgroup\$ – Dr Coconut Sep 29 '13 at 15:12
  • 2
    \$\begingroup\$ Frankly, I'd look into buying the I2C peripheral you need. Many have settable addresses. The one you have might even have a settable addy, but you don't have the docs to find out. Couple of bucks makes your problem go away \$\endgroup\$ – Scott Seidman Sep 30 '13 at 3:12
  • 1
    \$\begingroup\$ @Dr Coconut: try a BS170 instead of your IRF. \$\endgroup\$ – Laszlo Valko Oct 1 '13 at 16:39
4
\$\begingroup\$

Use a "bus switch" (i.e. NC7SZ384). They are more reliable for I2C switching, and have lower parasitic capacitance than a discrete MOSFET, and not that much more expensive.

\$\endgroup\$
3
\$\begingroup\$

Okay, I have solved my problem. Thank you all for your help!

My solution is as follows. I went down to Farnell and picked up some 2N7000 and some BS170 MOSFETs. I then replaced the IRF520 in my circuit (diagram in question) with the new MOSFETs and lo and behold, I was getting fabulous results with both of them at 400kHz I2C.

So that settles, it, thank you all once again!

\$\endgroup\$
2
\$\begingroup\$

Here is possibly why it did not work for you initially, and why folks should be careful using MOSFETs for this type of application (I2C and anything capacitance / rise-time sensitive):

IRF530 Datasheet Snippet

Recall that MOSFET output capacitance is Cgd + Cds. That 250pF is extremely high considering the I2C specification limits you to 400pF overall on the bus, lower to meet certain rise-time requirements. To be fair, this is more of a killer when you've got the MOSFET hooked up as a level shifter, but could still be an issue here.

Alternately (as mentioned below), there's a body diode to consider. For the IRF part, it has a maximum forward voltage of 2.5V.

enter image description here

Your BS170 is better:

BS170 Datasheet

Couldn't find a body diode voltage spec, but it might be different enough that here's the reason you're working. Using a MOSFET here, remember your circuit actually looks like:

enter image description here

The device will still see SDA through that body diode, and remembering that I2C is open-collector, if it decides to pull-low, it will sink current through that diode. The sensor will turn on its internal N-channel driver, pull SDA low, and now current can flow through the body diode (assuming a 3.3V bus or something above it's drop) and into the part, wrecking your bus.

I'm glad it's working for you right now, but in the future, you may want to consider not using MOSFETs, as described in this answer here. An analog switch IC or and I2C multiplexer device would be the "clean", but admittedly pricier way of doing this (in the case of the mux, anyway). With the analog switch, I would consider placing a very weak PU resistor (maybe 100K) on the SDA on the IC, as I have seen parts where floating I2C inputs are more likely to oscillate and burn current.

\$\endgroup\$
1
\$\begingroup\$

They make i2C bus repeater ICs for just this purpose.

\$\endgroup\$
  • \$\begingroup\$ It does seem a little overkill for my purpose considering that I really have no use for the buffers. Also, ordering a part like this would take ages to arrive where I live which is why I wanted to use a MOSFET which is easier to get. \$\endgroup\$ – Dr Coconut Sep 29 '13 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.