Connect with us

clever I2C/SPI switch: fail

Discussion in 'Microcontrollers, Programming and IoT' started by pgib8, Nov 30, 2015.

Scroll to continue with content
  1. pgib8


    Jul 26, 2015
    I'm working with a microcontroller where I had to select the small version with fewest pins to save space. So now I have I2C and SPI sharing some of the same pins. If I want to use both, it's easy in firmware but more difficult on the hardware side. The SPI device(s) won't be an issue because they have dedicated chip-selects. The I2C devices on the other hand I need to isolate them while I'm talking through SPI. If I don't, the I2C device may erroneously interpret some of the SPI communication and even worse may pull one of the lines low while it's actively driven high by SPI (= short circuit).

    A quick recap of I2C: Each entity on the bus can only ever pull down the lines (clock and data). When nothing is pulling them down, pull-up resistors bring them to Vcc (3V). The idle state is when both lines are high.

    What I needed was a buffer with an enable function. On the left side is the microcontroller where the lines also join up with SPI. On the right side are all the I2C devices. When the buffer is enabled, the clock and data lines are passed through and either side can pull them low. When the buffer is not enabled, the 2 sides are isolated. The left side can do whatever it wants while the right side remains pulled-up and in idle. Should for some reason a device (right side) pull down one of the lines it would have no effect on the left side.
    I also know there are ICs that already do this, but they cost a lot compared to other components.

    So I designed this clever circuit, or so I thought. I finally got around to prototyping it and then realized it's not working. I spent hours building this thing, so that was frustrating but still better than to have the PCB manufactured and then realize the error.

    Let me not tell you right away why it's not working, then we can make it a puzzle. Let me just say that I failed to see the bigger picture.

    Now as to the solution, I got something figured out and it amazes me that I didn't think of it at the time because it's so much simpler.

    I will provide my answers shortly.
    i2c buffer - Copy (2).png
  2. dorke


    Jun 20, 2015
    1.You only need to switch SDA no need to do that for SCL
    (assuming your MCU provides SCL i.e is master).
    2.What you need is the simplest 1-line(SPST) analog switch.
    You can do that with very cheap Mosfets and a control line from the MCU...
    or use a 74HC4016 ,CD4066 etc analog switch.
  3. pgib8


    Jul 26, 2015
    And we have a winner: @dorke

    So yes, a simple relay is the perfect solution and I was severely over-complicating things.

    The reason the circuit didn't work is because it creates a never-ending feedback loop. Once a line is pulled low from one side, it will pull it low on the other side which in turn pulls it low on the original side. Once it's low, it can never come back out of it.

    And now a sad picture of a completely worthless work that couldn't even be a paper weight.

  4. GPG


    Sep 18, 2015
  5. dorke


    Jun 20, 2015
    Nice part, but rather expansive for that app.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day