Go Down

Topic: pinMode sets OUTPUT pins high by default? (Read 1 time) previous topic - next topic

cbeauvois

I apologize if there's a straightforward explanation/workaround for this (I searched but couldn't find any).

On the Due + Arduino 1.5.1, if I designate any digital pin as OUTPUT, that pin will also be set HIGH.

ex.

void setup() {
  // put your setup code here, to run once:
  pinMode(25, OUTPUT); 
}

On 2 separate Dues, I set an LED + 100k resistor to pin 25, which lit up on initialize. When commenting out the above, the LED remained dark.

I also ran the same code on a Mega and Duo and saw the opposite result, i.e. the pin was kept LOW after the pinMode call and the LED remained dark.

Is there any documentation where this is explained that I missed?
Is there a way to set the default on initialize for Due OUTPUT pins to LOW??

Thanks!


max3000

Hi

It happens to me too. If I put the instruction

pinMode(53, OUTPUT);

The pin 53 goes high. I have to put also the instruction digitalWrite(53, LOW); to init the pin 53 as output and low.

I'm going to read the datasheet of the AT91SAM3X8E because this is strange.

Bye

cbeauvois

Any word?

Too bad this isn't consistent with the AVR-based Arduino environment, but maybe there's an easy way to get the Due to set pins to LOW instead of HIGH on init?

Thanks!

#3
Mar 28, 2013, 06:45 am Last Edit: Mar 28, 2013, 06:50 am by rockwallaby Reason: 1
Reading the SAM3X main datasheet it says the following in section 32.5.1;
Quote
Pull-up Resistor Control
Each I/O line is designed with an embedded pull-up resistor. The pull-up resistor can be enabled
or disabled by writing respectively PIO_PUER (Pull-up Enable Register) and PIO_PUDR (Pull-up Disable Resistor).
Writing in these registers results in setting or clearing the corresponding bit in PIO_PUSR (Pull-up Status Register).
Reading a 1 in PIO_PUSR means the pull-up is disabled and reading a 0 means the pull-up is enabled.
Control of the pull-up resistor is possible regardless of the configuration of the I/O line.
After reset, all of the pull-ups are enabled, i.e. PIO_PUSR resets at the value 0x0.


Notice that it mentions all pull-ups are enabled after reset.
I wonder if maybe something has been overlooked in disabling pull-ups on setting pinMode(x, OUTPUT)?

cbeauvois wrote:
Quote
On 2 separate Dues, I set an LED + 100k resistor to pin 25, which lit up on initialize

I am surprised you were able to see any light emitting from the LED at all with a 100k? current limiting resistor, you must have exceptionally good eyesight ?

_____
Paul

cbeauvois

My bad, resistance was 1k; I confused this with the value of the internal (100k) pull-up.

m3741

See my post at http://forum.arduino.cc/index.php?topic=185230.0


Go Up