I’m getting odd and inconsistent errors when initializing GPIO pins.
I’ve reduced the code down the following to demonstrate the issues.
Always get the following error. But the error will inconsistently move to a different line if I move the order of initialization around.
Any ideas about what we are doing wrong ?
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####
#### Message:
#### GHIElectronics.TinyCLR.Devices.Gpio.Provider.GpioControllerApiWrapper::SetPinChangedEdge [IP: 0000] ####
#### GHIElectronics.TinyCLR.Devices.Gpio.Provider.GpioControllerApiWrapper::SetPinChangedHandler [IP: 0052] ####
#### GHIElectronics.TinyCLR.Devices.Gpio.GpioPin::add_ValueChanged [IP: 0020] ####
#### GPIO_Errors.Program::Main [IP: 0077] ####
Exception thrown: 'System.InvalidOperationException' in GHIElectronics.TinyCLR.Devices.Gpio.dll
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Pins;
using System.Diagnostics;
namespace GPIO_Errors
{
internal class Program
{
static void Main()
{
GpioPin _GPIOPin_Down = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PE0);
_GPIOPin_Down.SetDriveMode(GpioPinDriveMode.Input);
GpioPin _GPIOPin_Right = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PC9);
_GPIOPin_Right.SetDriveMode(GpioPinDriveMode.Input);
GpioPin _GPIOPin_Back = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA0);
_GPIOPin_Back.SetDriveMode(GpioPinDriveMode.Input);
GpioPin _GPIOPin_Up = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA5);
_GPIOPin_Up.SetDriveMode(GpioPinDriveMode.Input);
GpioPin _GPIOPin_Left = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PE1);
_GPIOPin_Left.SetDriveMode(GpioPinDriveMode.Input);
GpioPin _GPIOPin_Enter = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA9);
_GPIOPin_Enter.SetDriveMode(GpioPinDriveMode.Input);
_GPIOPin_Enter.ValueChanged += _GPIOPin_ValueChanged;
_GPIOPin_Right.ValueChanged += _GPIOPin_ValueChanged;
_GPIOPin_Left.ValueChanged += _GPIOPin_ValueChanged;
_GPIOPin_Up.ValueChanged += _GPIOPin_ValueChanged;
_GPIOPin_Back.ValueChanged += _GPIOPin_ValueChanged;
_GPIOPin_Down.ValueChanged += _GPIOPin_ValueChanged;
}
private static void _GPIOPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
Debug.WriteLine(sender.ToString());
}
}
}