Code to control GPIO outputs

Exactly the same code succeeds in driving GPIO on pin 13 of the Iris Board but produces no changes
on GPIO pins 15 and 17, although they are all GPIO by default and the same code is used for the three attempts…

Any ideas?

See the code below:

Init first

        hGpio = Gpio_Init((Int32*)0);
        Gpio_Open(hGpio);

Now toggle pin 15

        io = ((0x0020 << 16) + 103);        // Colibri SODIMM pin 103 (Iris pin 15)   
        Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
        Gpio_SetDir(hGpio, io, 1);  // Set GPIO Configured io as output
        Gpio_SetLevel(hGpio, io, 1); //set output to 1
        Gpio_SetLevel(hGpio, io, 0); //set output to 0

Didn’t work

Now try on 13

        io = ((0x0020 << 16) + 98);        // Colibri SODIMM pin 98 (Iris pin 13) 
        Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
        Gpio_SetDir(hGpio, io, 1);  // Set GPIO Configured io as output
        Gpio_SetLevel(hGpio, io, 1); //set output to 1
        Gpio_SetLevel(hGpio, io, 0); //set output to 0

Success!!

Now try on 17

        io = ((0x0020 << 16) + 97);        // Colibri SODIMM pin 97 (Iris pin 17)   
        Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
        Gpio_SetDir(hGpio, io, 1);  // Set GPIO Configured io as output
        Gpio_SetLevel(hGpio, io, 1); //set output to 1
        Gpio_SetLevel(hGpio, io, 0); //set output to 0

Nothing again

I quickly tried to reproduce this issue. I quickly rewrote the code a little bit, may be it is related to this. I was able to reproduce this issue. Please check with my code and make sure you are using the latest lib as well (I have used the 2.0 release)

Here my code:

     HANDLE hGpio = Gpio_Init(NULL);
     uIo io ;
     Gpio_Open(hGpio);

     //Now toggle pin 15
     io.GenericDefinition = IOCOLIBRIPIN(103);        // Colibri SODIMM pin 103 (Iris pin 15)   
     Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
     Gpio_SetDir(hGpio, io, ioOutput);  // Set GPIO Configured io as output
     Gpio_SetLevel(hGpio, io, ioHigh); //set output to 1
     Gpio_SetLevel(hGpio, io, ioLow); //set output to 0

     //Now try on 13
     io.GenericDefinition = IOCOLIBRIPIN(98);        // Colibri SODIMM pin 98 (Iris pin 13) 
     Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
     Gpio_SetDir(hGpio, io, ioOutput);  // Set GPIO Configured io as output
     Gpio_SetLevel(hGpio, io, ioHigh); //set output to 1
     Gpio_SetLevel(hGpio, io, ioLow); //set output to 0

    //Now try on 17
     io.GenericDefinition= IOCOLIBRIPIN(97);        // Colibri SODIMM pin 97 (Iris pin 17)   
     Gpio_ConfigureAsGpio(hGpio, io);  // Configure io as GPIO       
     Gpio_SetDir(hGpio, io, ioOutput);  // Set GPIO Configured io as output
     Gpio_SetLevel(hGpio, io, ioHigh); //set output to 1
     Gpio_SetLevel(hGpio, io, ioLow); //set output to 0
	 return 0;

I have finally discovered that some GPIO pins are set by default as tri-state.
Possibly GPIO-SetConfigString should be used to deselect tri-state?

In case others might have a similar problem, this has worked for me to change a pin from tri-state o non-tristate (C# code):

bool resultbool= Gpio_SetConfigString ( hGpio, io, IntPtr.Zero, “outmode=std”, 1 ) ;

I can now drive the GPIO pin using Gpio_SetLevel.

@Henry: If you use Gpio_ConfigureAsGpio with the latest lib, it automatically should de-tristate the pin. If this workarround is still used, there is something wrong. Let me know if you need any further help.

@samuel.tx Thanks. You are right, with the latest lib setconfigstring is not necessary anymore.