GPIO PROBLEM for DETECT A RAISE


#1

Hello,

I 'm trying to detect a external interruption. For do this thing, I have selected the GPIO 24 and i use this code

#define NUM_GPIO_IN 1

#define READ_SIZE 8

u8  DataBuffer[READ_SIZE];

extern u32 spi_handler;

/* HANDSHAKE BUS CONFIG. FOR CONTROL THE COMUNICATION PMC->WMP*/
adl_ioDefs_t Gpio_In_Config[NUM_GPIO_IN] = {
(ADL_IO_GPIO | 24 |ADL_IO_DIR_IN) };

s32 HandleGPIO,HandleGPIO_O;
s32 MyGpioEventHandle;

s32 ReadValue;

/*GPIO event handler*/
void MyGpioEventHandler ( s32 GpioHandle, adl_ioEvent_e Event, u32 Size, void *Param )
{
	switch ( Event )
	{
		/*the subscribed input states has changed*/
		case ADL_IO_EVENT_INPUT_CHANGED :

                        //I read the value of the GPIO 24 for know if I have a zero or a one

			ReadValue = adl_ioReadSingle (HandleGPIO,Gpio_In_Config);
			TRACE((1,"ReadValue = %d",ReadValue));
			TRACE((1,"change"));
		break;
	}

}


void InitGPIO ( void )
{
    // TODO Insert your task initialization code here
	//Subscribe to the event
	MyGpioEventHandle = adl_ioEventSubscribe (MyGpioEventHandler);

	//I see if I have any error in the ioEventSubscription
	TRACE (( 1, "handler returns %d", MyGpioEventHandle ));

	if (MyGpioEventHandle>='0')
	{
		TRACE (( 7, "BIEN" ));
	}
	switch(MyGpioEventHandle)
	{
		case ADL_RET_ERR_PARAM:
			TRACE (( 1, "if a parameter has an incorrect value" ));
		break;
		case ADL_RET_ERR_NO_MORE_HANDLES:
			TRACE (( 1, "no more GPIO handles are available" ));
		break;
		case ADL_RET_ERR_SERVICE_LOCKED:
			TRACE (( 1, "the function was called from a low level Interrupt handler" ));
		break;
	}
	//subscribe to the input GPIO
	HandleGPIO=adl_ioSubscribe(NUM_GPIO_IN,Gpio_In_Config,ADL_TMR_TYPE_TICK,1,MyGpioEventHandle);

	//I see if I have any error in the ioSubscription
	TRACE (( 1, "handler returns %d", HandleGPIO ));
	switch(HandleGPIO)
	{
		case ADL_RET_ERR_PARAM:
			TRACE (( 1, "if a parameter has an incorrect value" ));
		break;
		case ADL_RET_ERR_DONE:
			TRACE (( 1, "refers to the field 3.10.2.6 adl_ioError_e" ));
		break;
		case ADL_RET_ERR_NO_MORE_TIMERS:
			TRACE (( 1, "there is no timer available to start" ));
		break;
		case ADL_RET_ERR_NO_MORE_HANDLES:
			TRACE (( 1, "no more GPIO handles are available" ));
		break;
		case ADL_RET_ERR_SERVICE_LOCKED:
			TRACE (( 1, "the function was called from a low level Interrupt handler" ));
		break;
	}
/*
	HandleGPIO_O=adl_ioSubscribe(NUM_GPIO_OUT,Gpio_Out_Config,0,0,0);

	TRACE (( 1, "handler_O returns %d", HandleGPIO_O ));
	switch(HandleGPIO_O)
	{
		case ADL_RET_ERR_PARAM:
			TRACE (( 1, "if a parameter has an incorrect value" ));
		break;
		case ADL_RET_ERR_DONE:
			TRACE (( 1, "refers to the field 3.10.2.6 adl_ioError_e" ));
		break;
		case ADL_RET_ERR_NO_MORE_TIMERS:
			TRACE (( 1, "there is no timer available to start" ));
		break;
		case ADL_RET_ERR_NO_MORE_HANDLES:
			TRACE (( 1, "no more GPIO handles are available" ));
		break;
		case ADL_RET_ERR_SERVICE_LOCKED:
			TRACE (( 1, "the function was called from a low level Interrupt handler" ));
		break;
	}
*/
	ReadValue = adl_ioReadSingle (HandleGPIO,Gpio_In_Config );

	TRACE((1,"ReadValue = %d",ReadValue));

}

Is this code correct? I tried this code changing the GPIO and it detects that the GPIO is changing, but if I use the GPIO that I want, it doesn’t work. It’s possible that the problem could be that my port has value “1” only 0,128 ms? Do I have another option to receive the interruption? :question:

Thank you,

Andrés


#2

Can I use TCU or IRQ API’s??
If the answer is yes, how i configure this??
I’m reading the documentation and i don’t see very clear anything about this two API’s.

Thank you


#3

Hi

You can use the External Interrupt Service (Extint ADL Service) and IRQ service. Note that you must use an INT pin. The following code can be used to configure the services:

static s32 ExtIntHandle = ERROR;
static s32 IrqHandle = ERROR;
static bool b_ext_interrupt = FALSE;

static s8 pfk_initExtInt1 (void)
{
    s8 result = ERROR;

    adl_irqConfig_t IRQintConfig;

    // Set IRQconfiguration
    IRQintConfig.PriorityLevel = 0;
    IRQintConfig.Enable = TRUE;
    IRQintConfig.Options = ADL_IRQ_OPTION_AUTO_READ;

    // Subscribes to the IRQ service - low level interrupt
    IrqHandle = adl_irqSubscribeExt(pfk_ExtIntHandler, ADL_IRQ_NOTIFY_LOW_LEVEL, &IRQintConfig);

    if(IrqHandle < 0)
    {
        TRACE((PIC_SPI_TRACE_LEVEL, "[pfk_initExtInt1] IRQ Service Initialisation ERROR: %d", IrqHandle));
        result = ERROR;
    }
    else
    {
        adl_extintConfig_t extintConfig;

        // ExtInt configuration: Falling Edge
        extintConfig.Sensitivity = ADL_EXTINT_SENSITIVITY_FALLING_EDGE;
        extintConfig.Filter = ADL_EXTINT_FILTER_BYPASS_MODE;
        extintConfig.FilterDuration = 0;
        extintConfig.Pad = 0;

        // Subscribe to External interrupt.
        ExtIntHandle = adl_extintSubscribe(1, IrqHandle, 0, &extintConfig);

        if (ExtIntHandle > 0)
        {
            TRACE((1, "[pfk_initExtInt1] External Interrupt initialisation OK"));
            result = OK;
        }
        else
        {
            TRACE((1, "[pfk_initExtInt1] External Interrupt initialisation ERROR %d %d", IrqHandle, ExtIntHandle));
            result = ERROR;
        }
    }

    return result;
}

static bool pfk_ExtIntHandler (adl_irqID_e Source, adl_irqNotificationLevel_e NotificationLevel,
        adl_irqEventData_t * Data)
{
    // An external interrupt was triggered - Set a flag and check it in a timer loop.
    b_ext_interrupt = TRUE;

    return TRUE;
}

#4

Thanks tomridl,

That means that if I use your solution i can’t use the GPIO 24 (I think is not a internal PIN, Do I am in the rigth thing :question: ) I need use the GPIO 24 because i can’t change the interconnections :cry:


#5

To use the external interrupt service, you must use a pin multiplexed with an INT. Check the Specification for the module you are using (on a WMP100 you can’t use GPIO24 as it is not an external interrupt).

Do you need to react instantly to the interrupt, or can you process it at a later stage? If you can process it later, you can use the TCU service in Event Capture mode. Every time the interrupt triggers it will increment a counter, and you can read and reset this counter at a periodic interval. Search for Event Detection Service in the ADL user guide for more information.


#6

thank you,

At the end, i have used an external interruption and it works well. (the only problem its that i have to do a new design of my PCB :cry: )
I search in all the documentation and i didn’t find anything about it. I think that my first code works well because it was working with others GPIO’s and probably my GPIO24 don’t work well :imp: :confused:

A lot of thanks


#7

Shouldn’t the fact that the minimum polling interval of GPIOs is 18ms have been something of a clue :question:


#8

Yes, the GPIO polling intercal is 18,5ms (but my interruptions were biggers) i think that my problem was that my GPIO didn’t works well :cry:

Thank you