Wired OR - Active Low Configuration

I want to configure a 328P pin so that it is only and active low output. It is connected in a wired OR reset circuit so I never want it to drive high. This could cause contention with other devices.

There is an external R tied to 3.3V (All logic is 3.3V)

With many devices, this can be accomplished by setting an output low and then just changing pin direction from input to output.

I am trying to make sure I understand the PinMode and digitalWrite or digitalWriteFast functions correctly.

From what I gleaned from digitalWrite, it operates differently depending on whether pinMode is set as an input or output.

How do you insure that setting pinMode as an output will not cause the port to drive high before a digitalWrite command executes. When pinMode is set to an output, is there an automatic high or low drive state?

BTW, I certainly know I could add a FET on transistor. I would like to avoid this.

Assuming, for example, Pin 7 on an Arduino Uno:

void setup() {
  // Initialize output to Hi-Z
  DDRD &= ~(1<<DDD7);
  PORTD &= ~(1<<PORTD7);
}

void loop() {
  // Pull output low
  DDRD |= (1<<DDD7);

  // Set output to Hi-Z
  DDRD &= ~(1<<DDD7);
}

I certainly know I could add a FET on transistor. I would like to avoid this.

Or a DIODE to create a DIODE-OR circuit

Thanks gfvalvo for the code snippet.

I think a variation of this will work.

Thanks lastchancename as well. I should have mentioned the diode logic option in my original post. This is another easy workaround. I don't want to revise my PCB, but this is a very easy way that works with the built in functions.

Just be careful there is no way for a driven pin to be tied directly to ground in any way.

I looked at the Atmel datasheet to understand everything a bit better.

Here is what I figured out.

If you Clear PORTxn when the DDxn is set as an input, the input is tristate. The more important piece is that when you toggle DDxn to output. It will output Low.

If you Set PORTxn when the DDxn is set as an input, you may enable a pullup that can't help you. Toggling DDxn to output will then drive the output High! before you can write DDxn for a low state.

This means you need an external pullup R in your circuit. You cannot use the internal Atmel one.

Obviously gfvalvo understood this, but it is an idiosyncrasy with the Atmel parts. Most devices that I have used don't have the pullup enabled this way (but do allow you to write the equivalent of PORTxn without the output direction set)

I think this also means you could use the standard functions with less efficiency

pinModeFast(pin,INPUT); // Set for tristate
digitalWriteFast(pin, LOW);

pinModeFast(pin,OUTPUT); // Active Low

where pin is the specific pin definition you want.

1 Like

aclark:
I think this also means you could use the standard functions with less efficiency

Perhaps. But why would you?