Skip to content

digitalWrite() unnecessarily activates the pull-up resistor on the specified pin #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BlackBrix opened this issue Jan 19, 2016 · 3 comments

Comments

@BlackBrix
Copy link

digitalWrite() unnecessarily activates the pull-up resistor on the specified pin.

the issue with the pull-up in digitalWrite(),
(other than the fact that this line shouldn't be there),
is because the pin configuration register (PINCFG) isn't logically ORed with the bit mask when the pull-up bit (PULLEN) is enabled,
instead the mask is copied directly into the register.
This effectively clears all the other bits in the register including the input enable (INEN).

in addition this issue makes the code not forward/backward compatible to AVR code
(digitalRead therefore cannot read back the current value of a digital PIN configured as OUTPUT.)

--> https://forum.arduino.cc/index.php?topic=367517.msg2534096#msg2534096
--> http://forum.arduino.cc/index.php?topic=334073.msg2306580#msg2306580

@spiderkeys
Copy link
Contributor

I also commented out that line in digitalWrite(), since our custom board has its own pull-up resistors and it was just unnecessarily pulling down the current on many of the lines.

  PIO_INPUT,            /* The pin is controlled by PORT and is an input. */
  PIO_INPUT_PULLUP,     /* The pin is controlled by PORT and is an input with internal pull-up resistor enabled. */
  PIO_OUTPUT,           /* The pin is controlled by PORT and is an output. */

I think it might be prudent to add one more PIO type here, PIO_OUTPUT_PULLUP, and have the functions in the wiring files respect that, or add a separate property in the pin description structure for resistor configuration altogether.

Nothing critical, but it had me scratching my head for a bit, wondering why my LED was barely turning on.

@sandeepmistry
Copy link
Contributor

@dirk67 the goal of enabling the pull-up was to maintain compatibility with AVR core behaviour:

The following is equivalent to pinMode(pin, INPUT_PULLUP); on AVR:

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

However, as you mentioned above, the core is currently clears input enable, so this does not work.

@dirk67 @spiderkeys I've submitted #101 to resolve this, please review and/or test it out if you have time.

mattairtech added a commit to mattairtech/ArduinoCore-samd that referenced this issue Mar 30, 2016
@sandeepmistry
Copy link
Contributor

Closing since #101 is merged now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants