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.


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.

  • \$\begingroup\$ The data pin needs to be pulled high, but not necessarily the clock. \$\endgroup\$ – Erik Friesen Mar 19 '14 at 10:19
  • \$\begingroup\$ Why is that? Well, I guess, if you only have one master, don't account for slave-induced clock stretching, etc. \$\endgroup\$ – Dzarda Mar 19 '14 at 10:24
  • \$\begingroup\$ Why switching between LOW/HiZ is rather than switching between LOW/HIGH states of the pin? \$\endgroup\$ – Akshara Prasad Jun 7 '15 at 3:56
  • \$\begingroup\$ 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. \$\endgroup\$ – Tom Carpenter Jun 7 '15 at 4:07
  • \$\begingroup\$ @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. \$\endgroup\$ – supercat May 25 '16 at 18:45

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.