# Gpio setting

**URL:** <https://forum.sierrawireless.com/t/gpio-setting/3864>\
**Category:** Legacy AirPrime modules\
**Created:** [November 16, 2009, 4:41pm UTC](https://forum.sierrawireless.com/t/gpio-setting/3864 "2009-11-16T16:41:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![foxalarm](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@foxalarm](https://forum.sierrawireless.com/u/foxalarm)\
**Post date:** [November 16, 2009, 4:41pm UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/1 "2009-11-16T16:41:11Z")

</div>

HI,i’m using a Q64 module and i must set up 2 pin, 1 IN / 1 OUT.I have realized this example making reference to Q64/WMP100 signals matching table.

```auto
#include "adl_global.h"

#define GPIO_OUTPUT_PIN 19
#define GPIO_INPUT_PIN 21

// GPIO service handle
static s32 MyGPIOHandle_OUT;
static s32 MyGPIOHandle_IN;
s32 ReadValue;
adl_ioDefs_t GpioConfig_OUT = ADL_IO_GPIO | GPIO_OUTPUT_PIN | ADL_IO_DIR_OUT;
adl_ioDefs_t GpioConfig_IN = ADL_IO_GPIO | GPIO_INPUT_PIN | ADL_IO_DIR_IN;

const u16 wm_apmCustomStackSize = 1024*3;

s32 MyGpioEventHandle;

void MyGpioEventHandler ( s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void * Param ){

	s32 ReadValue_IN;
	s32 ReadValue_OUT;

	TRACE (( 1, "EVENT" ));

// Check event
switch ( Event ){

	case ADL_IO_EVENT_INPUT_CHANGED :
		//...
	}
}

// ***MAIN*** //

void adl_main ( adl_InitType_e InitType ){
    adl_ioWriteSingle ( MyGPIOHandle_OUT, &GpioConfig_OUT, FALSE );
   adl_ioWriteSingle ( MyGPIOHandle_IN, &GpioConfig_IN, TRUE );
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
    MyGpioEventHandle = adl_ioEventSubscribe (MyGpioEventHandler);
    MyGPIOHandle_OUT = adl_ioSubscribe ( 1, &GpioConfig_OUT, 0, 0, 0 );
    TRACE (( 1, "GPIO (%d): %d", GPIO_OUTPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
    MyGPIOHandle_IN = adl_ioSubscribe ( 1, &GpioConfig_IN, 1, 1, MyGpioEventHandle );
    TRACE (( 1, "GPIO (%d): %d", GPIO_INPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
}
```

In these conditions ReadValue = -3 (ADL\_RET\_ERR\_UNKNOWN\_HDL)…  
Instead if use command At+wiom=1, " GPIO19" , 1.1 for example,no problem…

if I try to change pin

```auto
#define GPIO_OUTPUT_PIN 3
#define GPIO_INPUT_PIN 16
```

ReadValue = 0 !!! but i have not more the matching of the pin…  
Help 🙂

Regards

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [November 16, 2009, 11:40pm UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/2 "2009-11-16T23:40:20Z")

</div>

Hiya,

In your main code, you haven’t subscribed to the ADL GPIO service before calling adl\_ioWriteSingle() and adl\_ioReadSingle() so your GPIO handles are undefined. Therefore the values of your handles are essentially ‘random noise’ - they contain watever value the RAM had in it when the CPU started.

Try something like this, instead (interleaved with your existing code…):

```auto
// ***MAIN*** //

// GPIO service handle
static s32 MyGPIOHandle_OUT = ERROR; // mark handles as 'unused'
static s32 MyGPIOHandle_IN = ERROR;

void adl_main ( adl_InitType_e InitType )
{
    // set up and connect to GPIO
    MyGpioEventHandle = adl_ioEventSubscribe (MyGpioEventHandler);
    MyGPIOHandle_IN = adl_ioSubscribe ( 1, &GpioConfig_IN, 1, 1, MyGpioEventHandle );
    TRACE (( 1, "GPIO_IN handle: %d", MyGPIOHandle_IN ));
    MyGPIOHandle_OUT = adl_ioSubscribe ( 1, &GpioConfig_OUT, 0, 0, 0 );
    TRACE (( 1, "GPIO_OUT handle: %d", MyGPIOHandle_OUT ));

    // operate on GPIO
    adl_ioWriteSingle ( MyGPIOHandle_OUT, &GpioConfig_OUT, FALSE );
    adl_ioWriteSingle ( MyGPIOHandle_IN, &GpioConfig_IN, TRUE );
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));

    TRACE (( 1, "GPIO (%d): %d", GPIO_OUTPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));

    TRACE (( 1, "GPIO (%d): %d", GPIO_INPUT_PIN, &GpioConfig_OUT ));
    ReadValue = adl_ioReadSingle (MyGPIOHandle_IN, &GpioConfig_IN);
    TRACE (( 1, "PIN IN : %d",ReadValue ));
}
```

Let us how you get on.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![foxalarm](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@foxalarm](https://forum.sierrawireless.com/u/foxalarm)\
**Post date:** [November 17, 2009, 8:04am UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/3 "2009-11-17T08:04:39Z")

</div>

Thanks Dave,  
i try your code, but I obtain the same error (-3),it is as if I cannot setting those pin.  
Help 🙂  
Regards

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.sierrawireless.com/u/davidc)\
**Post date:** [November 17, 2009, 9:34am UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/4 "2009-11-17T09:34:35Z")

</div>

Hiya,

I’ll load your code into a Q2686 module when I’m at work tomorrow. Stay tuned.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![foxalarm](https://avatars.discourse-cdn.com/v4/letter/f/b2d939/32.png) [@foxalarm](https://forum.sierrawireless.com/u/foxalarm)\
**Post date:** [November 17, 2009, 11:11am UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/5 "2009-11-17T11:11:33Z")

</div>

On q2686 all ok , I do not receive no error

---

<div class="post-metadata">

**Author:** ![paruthiv](https://avatars.discourse-cdn.com/v4/letter/p/eb8c5e/32.png) [@paruthiv](https://forum.sierrawireless.com/u/paruthiv)\
**Post date:** [November 23, 2009, 6:45am UTC](https://forum.sierrawireless.com/t/gpio-setting/3864/6 "2009-11-23T06:45:14Z")

</div>

Hi

On Q64, the GPIO mapping is different and hence it is not always that something which works on WMP would also work on Q64 … Just read the Q64 User Guide once or better still ask your Distributor for the concerned mapping of GPIOs on Q64.

cheers… 😃
