How to Read a GPIO pin?

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]

You are in luck!

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

Why do you pass
#include “adl_gpio.h”

#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.