2 lwgpio interrupt handlers for 2 different pins

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

2 lwgpio interrupt handlers for 2 different pins

Jump to solution
1,620 Views
albertcalpito
Contributor II

I've been trying to initialize 2 separate gpio pins to have 2 separate interrupt handlers, however they seem to only be linked to the 2nd handler i initialize.  Is there some hardware restriction I am missing where 2 pins of the same port must share 1 interrupt hander?  I am seeing that although they are different pins, that the lwgpio_int_get_vector function is returning the same value for both.

LWGPIO_STRUCT column_1;

LWGPIO_STRUCT column_2;

lwgpio_init(&column_1, (GPIO_PORT_B | GPIO_PIN17), LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
lwgpio_set_functionality(&column_1, 1);
lwgpio_set_attribute(&column_1, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
lwgpio_int_init(&column_1, LWGPIO_INT_MODE_RISING);
_int_install_isr(lwgpio_int_get_vector(&column_1), column_1_button_pressed_function, (void *) &column_1);
_bsp_int_init(lwgpio_int_get_vector(&column_1), 3, 0, TRUE);
lwgpio_int_enable(&column_1, TRUE);

lwgpio_init(&column_2, (GPIO_PORT_B | GPIO_PIN18), LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE);
lwgpio_set_functionality(&column_2, 1);
lwgpio_set_attribute(&column_2, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE);
lwgpio_int_init(&column_2, LWGPIO_INT_MODE_RISING);
_int_install_isr(lwgpio_int_get_vector(&column_2), column_2_button_pressed_function, (void *) &column_2);
_bsp_int_init(lwgpio_int_get_vector(&column_2), 3, 0, TRUE);
lwgpio_int_enable(&column_2, TRUE);


vector_value = lwgpio_int_get_vector(&column_1);
vector_value = lwgpio_int_get_vector(&column_2);

void column_1_button_pressed_function(void *pin)
{
  printf("1\r\n");
  lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}

void column_2_button_pressed_function(void *pin)
{
  printf("2\r\n");
  lwgpio_int_clear_flag((LWGPIO_STRUCT_PTR) pin);
}

Tags (3)
1 Solution
1,070 Views
c0170
Senior Contributor III

Hello albert calpito,

you almost answered your question. I would recommend read NVIC part in a reference manual. Each port has own interrupt handler which indicates that your two buttons on PORTB share same ISR.

There is even here a discussion about it and how they solved an identification which button was pushed in ISR.

Regards,

c0170

View solution in original post

0 Kudos
7 Replies
1,071 Views
c0170
Senior Contributor III

Hello albert calpito,

you almost answered your question. I would recommend read NVIC part in a reference manual. Each port has own interrupt handler which indicates that your two buttons on PORTB share same ISR.

There is even here a discussion about it and how they solved an identification which button was pushed in ISR.

Regards,

c0170

0 Kudos
1,070 Views
nikhilsarnaik
Contributor III

Hi I am having similar issue, can you please point to the discussion of how to resolve it.

Thanks

Nikhil

0 Kudos
1,070 Views
albertcalpito
Contributor II

I have just responded to the thread with some c and h files to solve this issue.

Thank you,

Sincerely,

Albert Calpito

Ayantra

47873 Fremont Blvd,

Fremont. CA 94538

<http://www.ayantra.com> www.ayantra.com

510-623-7526 Office

510-552-4399 Cell

510-623-7839

0 Kudos
1,070 Views
kyleyang
Contributor IV

Hi Albert

Many thanks for your sharing.

But still need your help.

I got an issue on lwevent settings.

I have assign a lwevent to a gpio.

But the handler task can not receive the lwevent even if interrupt occur and set the event.

0 Kudos
1,070 Views
kyleyang
Contributor IV

Hi Albert

Sorry for bother you.

I fix this issue just now.

I find that missing some address map code in the "register_gpio_file".

It is works fine now.

Many thanks for your effort again.

0 Kudos
1,070 Views
nikhilsarnaik
Contributor III

Thanks Albert for your info, I fixed it, it was error in my code. I was not clearing the correct interrupt flag.

Nikhil

0 Kudos
1,070 Views
albertcalpito
Contributor II


Hello Nikhil,

Please see the attached files.  I've written an init function that will map interrupt events for the gpio's to their specific interrupt handlers.  The interrupt handlers will set the event that was specified in the init structure.

I've tested this for a few gpios at a time, and basic functionality seems to be working.