Skip to content
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

Disable pull-up/pull-down when setting pin as input #332

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

giampiero7
Copy link
Contributor

In pinMode() I think it would be better to call gpio_disable_pulls() on the ulPin when ulMode == INPUT.
As a case for the modification, consider the following code:

#include "pico/stdlib.h"
#define RP_PIN 24

void setup() {
  Serial.begin(9600);
  pinMode(RP_PIN, INPUT);
  while(!Serial) ;
}

void loop() {
  Serial.println(digitalRead(RP_PIN));
  delay(1000);
}

On a generic RP2040 board, where GPIO24 is used as generic input, the above would not work in cases where the input is weakly driven up.
Adding gpio_disable_pulls(RP_PIN); after pinMode(RP_PIN, INPUT); solves the issue.

In `pinMode()` I think it would be better to call `gpio_disable_pulls()` on the ulPin when ulMode == INPUT.
As a case for the modification, consider the following code:

```
#include "pico/stdlib.h"
#define RP_PIN 24

void setup() {
  Serial.begin(9600);
  pinMode(RP_PIN, INPUT);
  while(!Serial) ;
}

void loop() {
  Serial.println(digitalRead(RP_PIN));
  delay(1000);
}
```

On a generic RP2040 board, where GPIO24 is used as generic input, the above would not work in cases where the input is weakly driven up.
Adding `gpio_disable_pulls(RP_PIN);` after `pinMode(RP_PIN, INPUT);` solves the issue.
Copy link
Owner

@earlephilhower earlephilhower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Good catch!

@earlephilhower earlephilhower merged commit 9bed598 into earlephilhower:master Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants