Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When bit-banging I2C using 2 PIO lines do these lines still need to be pulled high? Obviously using a dedicated I2C bus the lines must be pulled high as the pins are open-drain outputs but PIO pins aren't open-drain.

share|improve this question
up vote 3 down vote accepted

Yes, both lines need to be pulled high at all time.

Also, when bitbanging I2C, rather than switching the LOW/HIGH states of the pin, switch between LOW/HiZ by simply altering the DDR/DIR registers.

share|improve this answer
The data pin needs to be pulled high, but not necessarily the clock. – Erik Friesen Mar 19 '14 at 10:19
Why is that? Well, I guess, if you only have one master, don't account for slave-induced clock stretching, etc. – Dzarda Mar 19 '14 at 10:24
Why switching between LOW/HiZ is rather than switching between LOW/HIGH states of the pin? – Akshara Prasad Jun 7 '15 at 3:56
As this isn't an answer, it should probably be posed as its own question, or a comment on Dzarda's answer. But anyway, High-Z is used because I2C is a multi-device bus and is designed so that devices are only allowed to drive low, and then an external resistor pulls the line high - this means if one device is trying to output a 1 while another is driving a 0, then they don't short each other out - because the device trying to output a 1 is in High-Z and a resistor is pulling up for it. – Tom Carpenter Jun 7 '15 at 4:07
@TomCarpenter: For the case of a single master driving SPI devices that do not use clock stretching, using an actively driven clock is fine, provided that the time required for the passive pull-up on SDA to generate a rising edge is shorter than the minimum delay between releasing SDA and driving SCK high. – supercat May 25 at 18:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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