Boot up question

I wrote a simple program to see what happens on boot up with the pins I am using on a different program. When I look at the pin states on a signal analyzer I see that D19 is high all the time (3.28 volts measured). I assume that this may be because of an internal pullup. However, on boot, all the output pins go high for 1.1608 seconds, then they all go low. Is there any way I can prevent this high output condition on boot up?

// Program constants:
const byte pinD12 = 12;    // Output on pin D12, PB6, Output Compare 1B
const byte pinD11 = 11;    // Output on pin D11, PB5, Output Compare 1A
const byte pinD7 = 7;      // Output on pin D7, PH4, Output Compare 4B
const byte pinD6 = 6;      // Output on pin D6, PH3, Output Compare 4A
const byte pinD5 = 5;      // Output on pin D5, PE3, Output Compare 3A
const byte pinD19 = 19;    // ISR input on pin D19, INT2 
const byte pinD45 = 45;    // Output on pin D45, PL4
const byte pinD49 = 49;    // Output on pin D49, PL0

void pinD19Interrupt()
{
  //No code here
}

void setup()
{
  pinMode(pinD12, OUTPUT);         // Declare  pinD12 an output
  digitalWrite(pinD12, LOW);       // Initialize pinD12 LOW 
  pinMode(pinD11, OUTPUT);         // Declare  pinD11 an output
  digitalWrite(pinD11, LOW);       // Initialize pinD11 LOW
  pinMode(pinD7, OUTPUT);          // Declare  pinD7 an output
  digitalWrite(pinD7, LOW);        // Initialize pinD7 LOW
  pinMode(pinD6, OUTPUT);          // Declare  pinD6 an output
  digitalWrite(pinD6, LOW);        // Initialize pinD6 LOW
  pinMode(pinD5, OUTPUT);          // Declare  pinD5 an output
  digitalWrite(pinD5, LOW);        // Initialize pinD5 LOW
  pinMode(pinD45, OUTPUT);         // Declare  pinD45 an output
  digitalWrite(pinD45, LOW);       // Initialize pinD45 LOW
  pinMode(pinD49, OUTPUT);         // Declare  pinD49 an output
  digitalWrite(pinD49, LOW);       // Initialize pinD49 LOW
  attachInterrupt(digitalPinToInterrupt(pinD19), pinD19Interrupt, FALLING); // Attach pinD19 to pinD19 Interrupt() ISR function, interrupt on falling edge       
}

void loop()
 {
  // No code here.
}

Which board and CPU? I guess PH3 implies an Arduino Mega (Atmega2560)? (But 3.28V "high" implies otherwise...)

Are you sure the pins go high, rather than just "float" in high impedance state? Immediately after reset, and during the bootloader check for new sketch, all the pins are normally in input mode, which means they aren't driven at all. (most bootloaders will be careful not to do anything to pins that they're not actually using.)
You'd need physical "pull" resistors to ensure a particular state during that time period.

What you are describing is normal with most any processor. When reset It has no clue as to what is connected to what so it turns the ports off (Tristate or input) processor dependent. The program then configures the ports to what it was programed to. Then the program commands the outputs to be HIGH or LOW. During this transition you have no control with the processor.

The solution is to add resistors to pull the port pin into the desired level. You see this recommended a lot when MOSFETs are used as they can fry when in that intermediate state, to use pull down resistors. That is generally a 10K resistor connected to the port pin and ground. This keeps the output level LOW for the reset process until the program takes control .

Several processors actually read the level on some ports to determine there boot sequence. This is quite common on the ESP processors. You will find you can use the port pins but they need to be in a given state for reset.

Sorry, I should have mentioned that it is a Mega 2560. I double checked the voltage and it is real at ~3.28 volts. VDD to ground measures just a tad over 5 volts.

I tried a 10K pull down on an output pin. That seemed to cure the high initial state, yet still allows the pin to go high when I command it to do so. I have no formal training in electronics or microcontroller programming, so I'm kind of self taught and still very much learning. I had read someplace that all unused output pins should be tied to ground, but I hadn't heard about using pull downs on pins being used. It does make sense though. Does the 2560 have an option for an internal pull down resistor or is an external resistor the only way to do it?
Thanks so much for the information.

There is an internal option for it, but the sane problem will occur if you use the internal pull-up resistors (Logically, they aren't configured at boot).

I have had a lots of years experience and I still learn something every day. Electronics if not old it keeps growing.

DO NOT do this to "unused output pins". Directly wiring a pin to either ground or 5V, or 3.3V, means that if it is inadvertently programmed as an output later on without removing that connection, it's very likely it will be set to the opposite state(i.e. wired low, but programmed as a 1, or wired high, but programmed as a zero), and will be damaged.

You may certainly pull any unused pin to GND or to VCC with a pullup/pulldown resistor. Saving on resistors by wiring many pins to the same resistor for pullup/pulldown is false economy in my books, but may be done if minimal cost is important.

In fact the wiring will be wrong in that way more than nine times out of ten. :expressionless:

a7

Sorry, I should have specified through a resistor. On that subject, what is the highest value that would work but still allow a commanded high state to work?

infinite. The higher the resistance, the less effect it has on the pin state.

Not for a Mega (or other AVR).

So I suppose a bit of trial and error would be in order. Perhaps start with 10K and keep increasing until the pin no longer stays low on boot up, then back off a bit. Sound logical?

The internal pull-up resistors are documented as having an value of about 40k.
It'll depend somewhat on the environment; I've heard people claim that 40k is too high for some "noisy" environments.

There's some controversy about what to do with unused pins. Turning on the internal pullups and leaving them as inputs should be fine for most cases. (and better than the default state of "input without pullups.)