WiringPi and pull down

Post Reply
lolipop
Posts: 8
Joined: Wed Aug 05, 2020 10:30 pm
languages_spoken: english
ODROIDs: C4
Has thanked: 0
Been thanked: 0
Contact:

WiringPi and pull down

Post by lolipop »

Hi,

I'm trying to get wiringpi to set a GPIO pulldown resistor on pin 3 of the GPIO connector, which I want to use as an input. So far, I've got nothing connected to that pin.

Using command-line (after reboot):
gpio readall -a

Code: Select all

 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 | ALT1 | 1 |  3 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
 |  494 |   9 |    SCL.2 | ALT1 | 1 |  3 |   P/U |  5 || 6  |       |    |   |      | GND(0V)  |     |      |
 |  481 |   7 | GPIO.481 |   IN | 1 |  0 |   P/U |  7 || 8  | P/U   | 0  | 1 | ALT1 | TxD1     | 15  | 488  |
 |      |     |  GND(0V) |      |   |    |       |  9 || 10 | P/U   | 0  | 1 | ALT1 | RxD1     | 16  | 489  |
 |  479 |   0 | GPIO.479 |   IN | 1 |  0 |   P/U | 11 || 12 | P/U   | 0  | 1 | IN   | GPIO.492 | 1   | 492  |
 |  480 |   2 | GPIO.480 |   IN | 1 |  0 |   P/U | 13 || 14 |       |    |   |      | GND(0V)  |     |      |
 |  483 |   3 | GPIO.483 |   IN | 1 |  0 |   P/U | 15 || 16 | P/U   | 0  | 1 | IN   | GPIO.476 | 4   | 476  |
 |      |     |     3.3V |      |   |    |       | 17 || 18 | P/U   | 0  | 1 | IN   | GPIO.477 | 5   | 477  |
 |  484 |  12 |     MOSI | ALT4 | 1 |  3 |   P/U | 19 || 20 |       |    |   |      | GND(0V)  |     |      |
 |  485 |  13 |     MISO | ALT4 | 1 |  3 |   P/U | 21 || 22 | P/U   | 0  | 1 | IN   | GPIO.478 | 6   | 478  |
 |  487 |  14 |     SLCK | ALT4 | 1 |  3 |   P/U | 23 || 24 | P/U   | 0  | 1 | OUT  | SS       | 10  | 486  |
 |      |     |  GND(0V) |      |   |    |       | 25 || 26 | P/D   | 0  | 1 | OUT  | GPIO. 23 | 11  | 23   |
 |  474 |  30 |    SDA.3 |   IN | 1 |  0 |   P/U | 27 || 28 | P/U   | 0  | 1 | IN   | SCL.3    | 31  | 475  |
 |  490 |  21 | GPIO.490 |   IN | 1 |  0 |   P/U | 29 || 30 |       |    |   |      | GND(0V)  |     |      |
 |  491 |  22 | GPIO.491 |   IN | 1 |  0 |   P/U | 31 || 32 | P/D   | 0  | 0 | IN   | GPIO. 24 | 26  | 24   |
 |  482 |  23 | GPIO.482 |   IN | 0 |  0 |   P/D | 33 || 34 |       |    |   |      | GND(0V)  |     |      |
 |  495 |  24 | GPIO.495 |   IN | 0 |  0 | DSBLD | 35 || 36 | P/D   | 0  | 1 | OUT  | GPIO. 22 | 27  | 22   |
 |      |  25 |    AIN.2 |      |   |    |       | 37 || 38 |       |    |   |      | 1V8      | 28  |      |
 |      |     |  GND(0V) |      |   |    |       | 39 || 40 |       |    |   |      | AIN.0    | 29  |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
Then:

Code: Select all

gpio mode 8 input
gpio mode 8 down
gpio readall -a
Gives me:

Code: Select all

 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 | ALT1 | 1 |  3 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
Note how the mode is still ALT1, but it indicates pulldown, however the value is 1. Weird when nothing is connected to the pin and it has a pull down.

Now let's do this:

Code: Select all

gpio mode 30 input
gpio mode 30 down
gpio mode 21 input
gpio mode 21 down
gpio readall -a
Result:

Code: Select all

 |  474 |  30 |    SDA.3 |   IN | 1 |  0 |   P/D | 27 |
 |  490 |  21 | GPIO.490 |   IN | 0 |  0 |   P/D | 29 |
So it seems it that on SDA.3, I can change the mode to INPUT, but the value is still 1. And when I enable pulldown on 21 which has no other mode, value actually switches to 0.




Here's a tiny test C program:

Code: Select all

#include <wiringPi.h>

#define PIN 8

int main(int argc, char* argv[])
{
  wiringPiSetup();
  pinMode(PIN, INPUT);
  pullUpDnControl(PIN, PUD_DOWN);
  printf("PUD: %d\n", getPUPD(PIN));
  printf("Status: %s\n", ::digitalRead(PIN) == HIGH ? "HIGH" : "LOW");
}
Running it outputs:

Code: Select all

PUD: 2
Status: HIGH
(PUD 2 = pullup... 1 = pulldown)

Now changing the pin to 30 gives me the same, and then to 21 gives:

Code: Select all

PUD: 2
Status: LOW
And after that, here's the result of gpio readall -a:

Code: Select all

 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 | ALT1 | 1 |  3 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
 |  494 |   9 |    SCL.2 | ALT1 | 1 |  3 |   P/U |  5 || 6  |       |    |   |      | GND(0V)  |     |      |
 |  481 |   7 | GPIO.481 |   IN | 1 |  0 |   P/U |  7 || 8  | P/U   | 0  | 1 | ALT1 | TxD1     | 15  | 488  |
 |      |     |  GND(0V) |      |   |    |       |  9 || 10 | P/U   | 0  | 1 | ALT1 | RxD1     | 16  | 489  |
 |  479 |   0 | GPIO.479 |   IN | 1 |  0 |   P/U | 11 || 12 | P/U   | 0  | 1 | IN   | GPIO.492 | 1   | 492  |
 |  480 |   2 | GPIO.480 |   IN | 1 |  0 |   P/U | 13 || 14 |       |    |   |      | GND(0V)  |     |      |
 |  483 |   3 | GPIO.483 |   IN | 1 |  0 |   P/U | 15 || 16 | P/U   | 0  | 1 | IN   | GPIO.476 | 4   | 476  |
 |      |     |     3.3V |      |   |    |       | 17 || 18 | P/U   | 0  | 1 | IN   | GPIO.477 | 5   | 477  |
 |  484 |  12 |     MOSI | ALT4 | 1 |  3 |   P/U | 19 || 20 |       |    |   |      | GND(0V)  |     |      |
 |  485 |  13 |     MISO | ALT4 | 1 |  3 |   P/U | 21 || 22 | P/U   | 0  | 1 | IN   | GPIO.478 | 6   | 478  |
 |  487 |  14 |     SLCK | ALT4 | 1 |  3 |   P/U | 23 || 24 | P/U   | 0  | 1 | OUT  | SS       | 10  | 486  |
 |      |     |  GND(0V) |      |   |    |       | 25 || 26 | P/D   | 0  | 1 | OUT  | GPIO. 23 | 11  | 23   |
 |  474 |  30 |    SDA.3 |   IN | 1 |  0 |   P/D | 27 || 28 | P/U   | 0  | 1 | IN   | SCL.3    | 31  | 475  |
 |  490 |  21 | GPIO.490 |   IN | 0 |  0 |   P/D | 29 || 30 |       |    |   |      | GND(0V)  |     |      |
 |  491 |  22 | GPIO.491 |   IN | 1 |  0 |   P/U | 31 || 32 | P/D   | 0  | 0 | IN   | GPIO. 24 | 26  | 24   |
 |  482 |  23 | GPIO.482 |   IN | 0 |  0 |   P/D | 33 || 34 |       |    |   |      | GND(0V)  |     |      |
 |  495 |  24 | GPIO.495 |   IN | 0 |  0 | DSBLD | 35 || 36 | P/D   | 0  | 1 | OUT  | GPIO. 22 | 27  | 22   |
 |      |  25 |    AIN.2 |      |   |    |       | 37 || 38 |       |    |   |      | 1V8      | 28  |      |
 |      |     |  GND(0V) |      |   |    |       | 39 || 40 |       |    |   |      | AIN.0    | 29  |      |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
So can anyone help me get these GPIOs into pulldown inputs? And does anyone know why getPUPD returns 2 (pullup) when gpio tool displays P/D ?

Thanks!

lolipop
Posts: 8
Joined: Wed Aug 05, 2020 10:30 pm
languages_spoken: english
ODROIDs: C4
Has thanked: 0
Been thanked: 0
Contact:

Re: WiringPi and pull down

Post by lolipop »

I'm investigating...

I've managed to get "wiringPi pin 8" into an input.

Code: Select all

 +------+-----+----------+------+---+----+---- Model  ODROID-C4 ----+----+---+------+----------+-----+------+
 | GPIO | wPi |   Name   | Mode | V | DS | PU/PD | Physical | PU/PD | DS | V | Mode |   Name   | wPi | GPIO |
 +------+-----+----------+------+---+----+-------+----++----+-------+----+---+------+----------+-----+------+
 |      |     |     3.3V |      |   |    |       |  1 || 2  |       |    |   |      | 5V       |     |      |
 |  493 |   8 |    SDA.2 |   IN | 1 |  3 |   P/D |  3 || 4  |       |    |   |      | 5V       |     |      |
At least according to "gpio". Now, even though it has a pulldown, it's still reported as "1".

To do so, I've played with the insides of the wiringPi lib, and somehting has caught my attention:

Code: Select all

#define C4_GPIO_BASE			0xFF634000
Yet, here's a quote from the SoC datasheet (p171):
The base address is 0xff634400 for PERIPHS_PIN_MUX_X
Seems like there's an inconsistency... who's right? I'd say 4000 is right, as it's the one used in wiringPi and in general the lib works, if it was misaligned by 0x400 I could certainly not control outputs nor read inputs.

I've found some other issue, like running this:

Code: Select all

  pullUpDnControl(PIN, PUD_DOWN);
  printf("PUD: %d\n", getPUPD(PIN));
Will output "2".

Code: Select all

  pullUpDnControl(PIN, PUD_UP);
  printf("PUD: %d\n", getPUPD(PIN));
Will output "1". And I'm pretty sure it's a but in the wiringpi C4 library.

_pullUpDnControl when called with PUD_UP sets a bit...
_getPUPD when the bit is set returns PUD_DOWN... I think it's just a silly mistake.

joshua.yang
Posts: 434
Joined: Fri Sep 22, 2017 5:54 pm
languages_spoken: Korean, English
ODROIDs: XU4, XU4Q + Cloudshell2, H2, N2
Has thanked: 27 times
Been thanked: 99 times
Contact:

Re: WiringPi and pull down

Post by joshua.yang »

Hi.

The four I2C pins, which are two pairs of I2C-2 and I2C-3, have external strong pull-up resistors on the board. For this reason, editing pull up/down registers using WiringPi doesn't affect its resulting outputs.

In the base address, why we use 0xFF634000 rather than 0xFF634400 is to omit the "multiplication/shift" operator when adding an offset address to the base address. Those are just prepared.

lolipop
Posts: 8
Joined: Wed Aug 05, 2020 10:30 pm
languages_spoken: english
ODROIDs: C4
Has thanked: 0
Been thanked: 0
Contact:

Re: WiringPi and pull down

Post by lolipop »

Thank you so much for your answer!
While we're at it, could you tell me if any other pin has external pullups or pulldown?

Side note: I chose a board from you guys for my project because I was under the impression you had better support than others.
However, I didn't expect such good support! Thank you!

User avatar
odroid
Site Admin
Posts: 35297
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 1089 times
Been thanked: 824 times
Contact:

Re: WiringPi and pull down

Post by odroid »

As far as I've seen the ODROID-C4 full schematics, only the I2C signals have the external pull-up resistors.
https://wiki.odroid.com/odroid-c4/hardw ... _datasheet

lolipop
Posts: 8
Joined: Wed Aug 05, 2020 10:30 pm
languages_spoken: english
ODROIDs: C4
Has thanked: 0
Been thanked: 0
Contact:

Re: WiringPi and pull down

Post by lolipop »

Sorry, my post didn't go... Saw the same on schematics...
And if you don't mind my asking, out of curiosity, why diodes on the 2nd I²C port? :)

User avatar
odroid
Site Admin
Posts: 35297
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English, Korean, Japanese
ODROIDs: ODROID
Has thanked: 1089 times
Been thanked: 824 times
Contact:

Re: WiringPi and pull down

Post by odroid »

Probably reducing the leak current when you use this RTC shield board?
https://www.hardkernel.com/shop/rtc-shield/
These users thanked the author odroid for the post:
tobetter (Fri Aug 28, 2020 5:56 pm)

Post Reply

Return to “Hardware and peripherals”

Who is online

Users browsing this forum: No registered users and 1 guest