# How to Read a GPIO pin?

**URL:** <https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863>\
**Category:** Open AT\
**Created:** [November 15, 2006, 8:09am UTC](https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863 "2006-11-15T08:09:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajendra](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@Rajendra](https://forum.sierrawireless.com/u/Rajendra)\
**Post date:** [November 15, 2006, 8:09am UTC](https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863/1 "2006-11-15T08:09:23Z")

</div>

Hi,

I am a beginner in OPEN AT. I can able to toggle a gpio, but when i want to read the status of the pin i am getting a error.

Does anybody have any example program of how to read a GPIO pin, kindly post here.

This is the program which i wrote.

#include “adl\_global.h”

u32 wm\_apmCustomStack [256];  
const u16 wm\_apmCustomStackSize = sizeof ( wm\_apmCustomStack );

s8 GpioHandle;

void check()  
{

```
s32 Returncode;
s8 ReadGPIO;
adl_ioUnsubscribe(GpioHandle);
ReadGPIO = adl_ioSubscribe(ADL_IO_Q24X6_GPIO_0,1,1,0,(adl_ioHdlr_f)NULL);
Returncode = adl_ioRead(ReadGPIO);
if(Returncode == ADL_RET_ERR_UNKNOWN_HDL)
    adl_atSendResponse(ADL_AT_RSP,"\r\n ADL_RET_ERR_UNKNOWN_HDL \r\n");
else if(Returncode == ADL_RET_ERR_FATAL)
    adl_atSendResponse(ADL_AT_RSP,"\r\n ADL_RET_ERR_FATAL \r\n");
else if(Returncode == ADL_RET_ERR_BAD_STATE)
    adl_atSendResponse(ADL_AT_RSP,"\r\n ADL_RET_ERR_BAD_STATE \r\n");
else
    adl_atSendResponse(ADL_AT_RSP,"\r\n Success \r\n");        

```

}

void adl\_main ( adl\_InitType\_e InitType )  
{  
s8 Returncode;  
TRACE (( 1, “Embedded : Appli Init” ));  
/\* Set 1s cyclic timer \*/  
GpioHandle = adl\_ioSubscribe(ADL\_IO\_Q24X6\_GPIO\_0,0,0,0,(adl\_ioHdlr\_f)NULL);  
Returncode = adl\_ioWrite(GpioHandle,ADL\_IO\_Q24X6\_GPIO\_0,0xFFFFFFFF);  
if(Returncode == ADL\_RET\_ERR\_UNKNOWN\_HDL)  
adl\_atSendResponse(ADL\_AT\_RSP,"\r\n ADL\_RET\_ERR\_UNKNOWN\_HDL \r\n");  
else if(Returncode == ADL\_RET\_ERR\_FATAL)  
adl\_atSendResponse(ADL\_AT\_RSP,"\r\n ADL\_RET\_ERR\_FATAL \r\n");  
else if(Returncode == ADL\_RET\_ERR\_PARAM)  
adl\_atSendResponse(ADL\_AT\_RSP,"\r\n ADL\_RET\_ERR\_PARAM \r\n");  
else if(Returncode == ADL\_ERR\_IO\_WRITE)  
adl\_atSendResponse(ADL\_AT\_RSP,"\r\n ADL\_ERR\_IO\_WRITE \r\n");  
else  
adl\_atSendResponse(ADL\_AT\_RSP,"\r\n SUCCESS\r\n");

```
adl_tmrSubscribe(TRUE,50,ADL_TMR_TYPE_100MS,check);

```

}

Output:

Success GPIO\_0 is high and after 5000ms it’s becoming LOW.

but the adl\_ioRead function returns only ADL\_RET\_ERR\_BAD\_STATE.

Kindly help me how to solve this problem.

Thanks & regards,  
Rajendra R  
[/code]

---

<div class="post-metadata">

**Author:** ![awneil](https://avatars.discourse-cdn.com/v4/letter/a/49beb7/32.png) [@awneil](https://forum.sierrawireless.com/u/awneil)\
**Post date:** [November 16, 2006, 12:15am UTC](https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863/2 "2006-11-16T00:15:56Z")

</div>

> [@Rajendra](#):
>
> Does anybody have any example program of how to read a GPIO pin

You are in luck!

There is just such an example included with the sanples provided by Wavecom:

> [@Wavecom](#):
>
> Telemetry - Application Description  
> This application checks some GPIO states every 3 seconds. On a state change, it sends a SMS report to the number set by the application

---

<div class="post-metadata">

**Author:** ![Anjey](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Anjey](https://forum.sierrawireless.com/u/Anjey)\
**Post date:** [February 2, 2007, 9:12am UTC](https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863/3 "2007-02-02T09:12:21Z")

</div>

Why do you pass  
#include “adl\_gpio.h”

---

<div class="post-metadata">

**Author:** ![tobias](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@tobias](https://forum.sierrawireless.com/u/tobias)\
**Post date:** [February 2, 2007, 10:13am UTC](https://forum.sierrawireless.com/t/how-to-read-a-gpio-pin/863/4 "2007-02-02T10:13:11Z")

</div>

#include “adl\_global.h”  
is enough to use as that will include gpio.h as well.

The program would not compile properly if it was not.
