chipKIT® Development Platform

Inspired by Arduino™

Default IO state on reboot

Created Mon, 18 Aug 2014 15:08:56 +0000 by lanmat


lanmat

Mon, 18 Aug 2014 15:08:56 +0000

This seems like something that should be sitting in a manual somewhere w/ asterisks around it, but I can't seem to find anything w/ my searching.

Is there a way to specify a pin's default state on reset? I thought they were all LOW, but I'm getting 3.3V on pin 15 on reboot, until it's initialized to 0V in the setup.

//For some reason, pin 15 is 3.3V here after reset
const int TTpin = 15;

void setup() {
  	Serial.begin(115200); 
	pinMode(TTpin, OUTPUT);		//Set Test Type output pin to an input
	digitalWrite(TTpin,LOW); //default to 100 opens testing resistor
//Pin 15 goes to 0V here, as expected
	Serial.println("Initialization Done.");
}

void loop() {	
}

It's not a big deal, it's just hooked up to a relay and it switches every time I connect to the COM port. Is there something special about certain pins that affects their default state? Just loading "blink" & probing that bank of outputs, I get: 14 LOW 15 HIGH 16 LOW 17 HIGH 18 LOW 19 LOW 20 HIGH 21 HIGH

Are these all set in some base code library?


sLowe

Mon, 18 Aug 2014 21:03:40 +0000

Hey lanmat,

I don't believe there is a way to set default states to each pin like you are describing. Some pins are used during reset to drive LED's and other functions the board is preforming.

A solution to your relay problem would be to have a pull down resistor from your pin and make sure that your pin isn't driving any LED's during reset. I have a consistent ground through reset working on an uno 32 pin 4. If I were to choose pin 13 on the uno, I would get the square wave that the pin supplies to an LED upon restart.

Hope this helps,

-Sam


lanmat

Tue, 19 Aug 2014 17:43:13 +0000

Ah! Excellent idea! Makes total sense I'd need to supply my own external pulldown resistor before the uC supplies it's own at the initialization phase when I set the pin to an output.


Jacob Christ

Tue, 19 Aug 2014 21:00:21 +0000

Most microcontroller pins default to High-Z out of reset, to know for sure you need to check the datasheet. chipKIT and Arduino boards have bootloaders. Bootloaders may change the state of any pin. The best place to look is the bootloader code to know for sure what any particular pin will do.

The other weird think about the Wiring API is that when you change a pin from input to output you cannot first tell the pin which stated you want it to be in when you do this, so you must do this:

pinMode(pin, OUTPUT); digitalWrite(pin, HIGH);

This will not work as expected:

digitalWrite(pin, HIGH); pinMode(pin, OUTPUT);

Jacob