trbotha
Posts: 18
Joined: Wed Dec 19, 2012 4:08 pm

RPI3 GPIO pin direction resetting

Thu Oct 19, 2017 1:13 pm

I'm using a RPI3 in a circuit using the GPIO for SPI, I2C and general GPIO pins. I'm using WiringPI to set the direction of GPIO4 (Physical pin 7, WiringPi pin 7) to set it as an OUTPUT pin and setting its state as HIGH. After setting the pin either via a C++ program or gpio in command line I verify the state using gpio readall and an oscilloscope. The pin is successfully set as an OUT pin (gpio readall) and the voltage is HIGH. After a few seconds the pin resets to an INPUT pin. This happens irrespective of doing it through the C++ program or via the command line utility gpio.

Driving another pin such as pin 23 succeeds with no resetting of the pin.

The only reason I can think of is that some other function periodically runs and resets the direction of the pin. However setting the state direction in a while loop in C++ does not seem to change its direction. Once the pin resets the program needs to be restarted for it to take action.

Any help is appreciated.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 4527
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: RPI3 GPIO pin direction resetting

Thu Oct 19, 2017 1:53 pm

WiringPI is going directly to the hardware, bypassing any knowledge of GPIO usage that the Linux kernel may have.

Most likely you have enabled something via config.txt that also thinks it is using GPIO4, and periodically it is checking it. Likely candidates would be a 1-wire interface as that defaults to GPIO4.
"sudo cat /sys/kernel/debug/pinctrl/pinctrl-handles may give you some more information on which driver has claimed the GPIO via Linux. Otherwise quote the whole of your config.txt (using code tags please).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

trbotha
Posts: 18
Joined: Wed Dec 19, 2012 4:08 pm

Re: RPI3 GPIO pin direction resetting

Mon Oct 23, 2017 12:28 pm

Thanks

Using sudo cat /sys/kernel/debug/pinctrl/pinctrl-handles provided the following

device: onewire@0 current state: default
state: default
type: MUX_GROUP controller pinctrl-bcm2835 group: gpio4 (4) function: gpio_i
type: CONFIGS_PIN controller pinctrl-bcm2835 pin gpio4 (4)config 00000000

This meant that the pin was controlled by the onewire interface commenting the following line in /boot/config.txt seems to have fixed the problem
#dtoverlay=w1-gpio

Return to “Interfacing (DSI, CSI, I2C, etc.)”

Who is online

Users browsing this forum: No registered users and 20 guests