# Is my reasoning about an ATMega328p connected to equipment requiring an open-drain pin correct?

I am part of a research group that is developing a concept for a PCB for an external piece of equipment. This piece of equipment can be controlled with a microcontroller. It communicates to my microcontroller through I2C, using SDA and SCL pins. However, it uses another pin; they call it an "interrupt pin" and it allows slaves to send commands to the master. The external piece of equipment states in its interfacing description that this interrupt pin should be controleld by an open-drain pin on a microcontroller. Fair enough.

Our microcontroller is an ATMega328p with Arduino bootloader. In prototyping I have abused Arduino's pinMode to emulate open-drain:

void setup ()
{
digitalWrite (pin, LOW) ;
}

void loop ()
{
...
pinMode (pin, OUTPUT) ; // drive pin low
...
pinMode (pin, INPUT) ; // hi-Z state
}


But as you probably know, this results in odd waveforms when the signals are checked with an oscilloscope. In the thread linked, the guy who ran into the same issue added an external 10k pullup to the pin and it solved his waveforms. It seemed to work correctly.

As none of us are very knowledgeable about this specific issue; are we correct in assuming that if a piece of external equipment requires control by an open-drain pin on "some microcontroller", this can be realized by switching INPUT/OUTPUT on an ATMega328p together with a 10k pullup resistor added to the pin?

Your "fake open drain" code (switching between low and high-Z) can indeed work as long as the supply voltage of the microcontroller is the same or higher than the voltage at that interface connection which requires the open drain.

If this condition is not met (the microcontroller uses a lower voltage) then the ESD diodes inside the microcontroller will start to conduct:

simulate this circuit – Schematic created using CircuitLab

To fix that I would try this:

simulate this circuit

For the NMOSFET I would start with a 2N7000, any other N-channel MOSFET might work as well as long as it has a low enough threshold voltage. Not that this inverts the behavior, if the microcontroller outputs a "1" then the NMOSFET will be "on" which will pull the input of the other device "low".

• It is indeed so that the device requiring the open-drain is of lower voltage. – Zimano Dec 11 '17 at 14:52
• Read carefully: if the device is using a lower supply voltage then the ESD diode does not have to be the issue. Also, the microcontroller might be working at a lower voltage than what you supply to it. Like an Arduino can be supplied by 5 V but internally use 3.3 V. Still, you can use the NMOS solution to solve this. – Bimpelrekkie Dec 11 '17 at 14:54
• My apologies, I forgot to close this question. Thanks again! – Zimano Jan 15 '18 at 21:50

Your assumptions and control methods are pretty much accurate.

However, depending on what the required open collector signal is and does, the fact that it appears to look odd on an oscilloscope does not necessarily indicate that something is wrong.

The thing you are driving may well be some form of current mode receiver, for example one side of an opto-coupler. As such, a pull-up does not provide any particular benefit other than making it easier to debug with the scope.

It really is a case by case situation.

As Bimpelrekkie mentions, it may also require open drain for voltage reasons. Careful reading and understanding of the attached object spec sheet is critical.

BTW: I believe the ATMega device has internal pull-ups that you can use through the pinMode command instead of an external resistor

• The ATMega has internal pullups indeed, but I was scared of the odd oscilloscope reading. The "external device" is under NDA, but it's used as an interrupt pin for I2C (alongside SCL and SDA). I have added this in the original question. – Zimano Dec 11 '17 at 14:47
• @Zimano It's okay to use the word "the" when you are talking about something that is known to everyone you are talking to. You are the only one who knows how the odd oscilloscope reading looks like. – Harry Svensson Dec 11 '17 at 14:48
• @HarrySvensson Indeed, my apologies. I didn't take any images. – Zimano Dec 11 '17 at 14:53

A output pin which is set low and then switched between enabled and Hi-Z behaves just like an open drain.
Where I have an issue is the

But as you probably know this results in ridiculously bad waveforms

I don't agree. An opendrain (or tri-state) output will not produce ridiculously bad waveforms. I know what you are referring to. If the signal connected to an opendrain (or tri-state) output is not driven it will start to float and follow any nearby signal source. Thus you wanted to add a pull-up resistor.
That is wrong. Strictly speaking a pull-up is NOT really part of an opendrain output. I suspect very much that your "equipment" will have a pull-up or equivalent in it. If not, that is a discrepancy between the requirements and what they really have.