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.