Shop OBEX P1 Docs P2 Docs Learn Events
Directly interfacing 5V I2C devices with 3.3V Prop — Parallax Forums

Directly interfacing 5V I2C devices with 3.3V Prop

RaymanRayman Posts: 14,876
edited 2009-12-06 00:31 in Propeller 1
I was able to connect a +5V DS1307 I2C RTC directly to the Prop's SDA and SCL lines and have it work properly.

This works because devices on the I2C bus just pull down these signals (they don't output anything).· It's as if they all have open collector I/O.

The problem is whether or not 3.3 V is enough for the device to register as a logic high or not...

The datasheet for the DS1307 says it just needs·2.2V for "logic 1 input".· But, other things, like I/O expanders·PCF8574 and PCA9554 are rated for 0.7*Vcc, which is 3.5 V.· Still, this might be close enough to work...

Anybody have luck directly connecting 5V I2C devices to the Prop?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-27 16:26
    Philips (now NXP), in their I2C Bus Specification (p. 43), shows a circuit that uses two MOSFETs for translating between different voltages on an I2C bus.

    -Phil
  • RaymanRayman Posts: 14,876
    edited 2008-02-27 16:34
    There are also chips that do it...

    I've used the PCA9512A (gives hot-swap ability) and the PCA9509 (easy pin arrangement)
    ·
  • crgwbrcrgwbr Posts: 614
    edited 2008-02-28 00:50
    According to this datasheet, the DS1307 has a min logical 1 of 2.2v. Thats plenty for the prop to work with.

    Regards,
    Craig

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My system: 1.6 GHz AMD Turion64 X2, 4GB DDR2, 256MB ATI Radeon Graphics card, 15.4" Widescreen HD Screen

    I have a duel boot of Ubuntu Linux and Windows Vista. Vista, because it came with the PC, Ubuntu because I like software that works.

    "Failure is not an option -- it comes bundled with Windows."

    Use The Best...
    Linux for Servers
    Mac for Graphics
    Palm for Mobility
    Windows for Solitaire
  • RaymanRayman Posts: 14,876
    edited 2008-02-28 17:21
    I think maybe this circuit might passively connect 3.3 and 5V devices...
    289 x 134 - 3K
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-28 19:23
    This will put the SDA line to 3.9 V which is insofar better than 3.3 V as the worstcase lowest TTL-HIGH "according to the book" is 3.7V
    It can be slightly improved by a diode at the prop rather than the 1k..

    Post Edited (deSilva) : 2/28/2008 8:21:14 PM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-28 19:29
    deSilva said...
    It can be slightly improved by a diode at the prop rather than the 1k.
    ??? SDA is bidirectional. Which direction should that diode point?

    -Phil
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-28 20:18
    Good question! Both directions?
    Sorry, bad thinking from me...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-28 20:55
    deSilva said...
    Both directions?
    Sure, why not? — so long as one of them is a three-terminal diode. smile.gif

    attachment.php?attachmentid=52424

    This is a simplified version of the two-transistor circuits posted here and here and is more or less the bipolar equivalent of the Philips' circuit mentioned above.. (Actually, either one of those would be better than my transistor/diode version.)

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 2/28/2008 9:01:15 PM GMT
  • RaymanRayman Posts: 14,876
    edited 2008-02-28 22:32
    I wonder if it has to be bi-directional... I think devices on the i2c bus merely have to pull down the voltage. For logic 1, the go high impedance and the pull-up resistor brings the bus voltage up... (I think this is the reason for the limitation on how much capacitance you're allowed to have on the bus).

    However, I think the voltage at the Prop, the way I drew it actually gets a bit bigger than 3.3V due to the drop across the internal protection transistor. So, I don't think a diode is necessary...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-02-28 22:53
    "Bi-directional" in this context refers to switching in the "horizontal" direction (Propeller<->I2C device), not in the "vertical" direction (Vss<->Vdd). The latter would more accurately be called "totem pole". The diode in the above circuit keeps the Propeller's internal I/O protection diode (to Vdd) from pulling down on the 5V side of the SDA line, while permitting the I2C device to pull down on the Propeller's line (but only to 0.6V above Vss). The transistor (common base connection) has to be there to allow the Propeller to pull the I2C device's line down, since the diode blocks that. So, yes, it needs to be bi-directional, with the diode handling one direction and the transistor taking care of the other.

    -Phil

    Addendum: BTW, this whole discussion is a subtopic of this thread and maybe should have gone there. Just so it doesn't get lost, I'll post a link there back to this thread.

    Post Edited (Phil Pilgrim (PhiPi)) : 2/28/2008 11:18:06 PM GMT
  • OctahedronOctahedron Posts: 18
    edited 2009-11-29 18:14
    I thought I would pass on a similar discussion on another thread.

    The FET cct. for 3.3v to 5.0v signal conversion shown above is available from http://www.hvwtech.com, stock code SKU# 50550 and is called a Logic Level Converter for a couple of bucks each. I have not tried it. If anyone has let me know how it worked out.

    As for the I2C discussions I think if they are true I2C devices then they do not supply voltage (passive device) and the associated current. They only drain to ground or pull down the voltage on the line when chatting. If 3.3 volts is the pull up voltage and that happens to be high enough to be recognizes as a 1 then it really what else it needed? The propeller should be used carefully because communicating with the output as an active supplier of voltage to a device, which is sinking current, may cause some troubles with the Prop output cct. and the receiver of the Prop current. It should really alternate between open (input which is 1) and sinking pull up voltage (zero) as an output only. I am working with some of these devices now and I will let you know if I run into problems. It does seem prudent to put a series resistor in the I2C lines just in case something wants to supply power to your Prop output or if you programmed and decided to make a "1" active from your end. There is a good little write up about I2C at: http://www.best-microcontroller-projects.com/i2c-tutorial.html

    So when coding I would think that something like:

    repeat 8 ' Output data to SDA
    ·· outa[noparse][[/noparse]SDA] := (data <-= 1) & 1
    ·· outa[noparse][[/noparse]SCL]~~ ' Toggle SCL from LOW to HIGH to LOW
    ·· outa[noparse][[/noparse]SCL]~

    May not be the best without series resistors. Instead, keep the output low and toggle between input and output to allow the pull up resisters to do their job. Like I said earlier I will give it a try and let you know if I run into trouble.

    Post Edited (Octahedron) : 11/29/2009 6:22:32 PM GMT
  • T ChapT Chap Posts: 4,223
    edited 2009-11-29 18:54
    I use PCF8574 and 8575 all the time directly to the prop, never have seen a problem out of maybe 100 boards that use these IC's.
  • OctahedronOctahedron Posts: 18
    edited 2009-12-05 23:06
    Did you use series & pull up resistors as shown above (See Rayman posted 2/28/2008 9:21 AM for diagram) with the i2cObjectv2 library from the object exchange? I was thinking of changing James Burrows code from active highs (one’s) to a passive input to conform to the I2C spec’s and allow the pull up resistors to do their job. I would think that you would not need the series resistors any more in the modified version.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-05 23:53
    When using Rayman's schematic you must include the pullups on both SDA and SCL and drive both open-drain. A 5V active high on the 5V side will overdrive anything on the 3.3V side through that 1K resistor. A 3.3V active high on the 3.3V side will only be 3.47V on the 5V side with the pullup; 3.3V without..

    -Phil
  • OctahedronOctahedron Posts: 18
    edited 2009-12-06 00:18
    Yes, it does have to be on both SDA and SCL lines. My point is: the library code (i2cObjectv2) has the output set to output voltage and it should not supply voltage only pull down voltage. By going between a high impedance state (in other words set as an input making the line high via the pull up resistor) and low by pulling down the voltage from the pull up resistor for zero (draining current). This gives the 1's and 0's by·initially setting the output low outa[noparse][[/noparse]pin] := 0 and toggling the pin between input and output using dira[noparse][[/noparse]pin] to give you the desired 1 and 0 (respectively) bit stream. This would make it conform to the I2C specifications.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (Octahedron) : 12/6/2009 12:59:52 AM GMT
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-12-06 00:31
    Right. That's what I meant by driving the bus "open-drain".

    -Phil
Sign In or Register to comment.