How to avoid short circuit when connecting a microcontroller and device using I2C bus

i2clogic-levelmicrocontrollershort-circuit

I am attempting to connect an 8051-compatible microcontroller to an accelerometer using the I2C bus. Both devices operate at the same voltage, 3.3v.
However, I am failing to understand something: won't a direct short be created when the microcontroller asserts a logic HIGH on either SCL or SDA and the slave device attempts to hold the line at logic LOW? I don't understand how to avoid this…

How can I make the MCU float the lines instead of placing a logic HIGH on them? I realize I can change the state of the lines to "input" instead of output, but is that safe to avoid a short circuit?

As I see it, the following scenario could happen:

If the MCU switched from 'input' mode to 'output' mode, couldn't the pin be in the HIGH state, even if you set the pin to LOW, then set input mode to 'output'? Won't the input voltage change the state back to HIGH due to the pin being in 'input' mode, before it has a chance to switch to output mode? Then for a few uS you would be outputting a logic high, before the MCU executed the next instruction to turn the pin to LOW.

Best Answer

Switching to input in order to float the line is completely acceptable. Microchip's PIC MCU's have done it this way for years. Only recently have they introduced devices that can be configured as open-drain.

Your MCU should have a separate control for input/output, and for the value of the output bit. The customary way to operate this is to set the output data to zero, and switch the direction bit (the one that determines input or output) instead. That is, make it an output to assert a zero, and make it an input to assert (suggest, really) a 1. Setting the bit to input also allows reading it; this and the "high" state are interchangeable.