Help setting up interrupt on GPIO

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

I was wandering if anyone could help me set up an interrupt on one of the GPIO pins, I've tried my self by following the hardware interface guide and i can't see where I've gone wrong. this is the code I've added to try and set this up. Whenever I try to compile i get to few arguments to function gpio_registerForInterrupt. Thanks

#define dial GPIO_PIN_P15


gpio_configurePin(0,dial,GPIO_EN_INT_RISING_EDGE|GPIO_PULL_DOWN,GPIO_PIN_INPUT_HIGH);


void hello_sensor_create(void)

{

 


   //each bit corresponds to a port for port 0 - 3

     UINT16 interrupt_handler_mask[3] = {0,0,0};

     //0 is the port with pin 15

     interrupt_handler_mask[0] |= (1 << dial);

     //register interrupt handler

     gpio_registerForInterrupt(interrupt_handler_mask,interrupt_gpio,NULL);


}

void interrupt_gpio(void*){


  if(led_on == FALSE){

                 gpio_setPinOutput(0,LED,GPIO_PIN_OUTPUT_HIGH);

                 gpio_setPinOutput(0,RGB,GPIO_PIN_OUTPUT_HIGH);

                 led_on = TRUE;

                 }else{

                   gpio_setPinOutput(0,LED,GPIO_PIN_OUTPUT_LOW);

                   gpio_setPinOutput(0,RGB,GPIO_PIN_OUTPUT_LOW);

                   led_on = FALSE;

                 }

}



0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello.

When you are initializing the mask array, try changing the "or" statement to an assignment.

I did a quick demo app of what I think is what you are trying to do.

The external button will turn the external LED on and off, while the on-board button will do the same for the on-board LED.

Take a look at it for reference.

pastedImage_0.jpg

Please let us know if this solved your problem.

Thank you.

James

View solution in original post

15 Replies
Anonymous
Not applicable

s.muyaba try taking a look at WICED Smart User's Guide -> GPIO -> interrupts.  First link should be sufficient to answer your question. 

-Kevin

0 Likes
JacobT_81
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

s.muyaba

The GPIOs you use to toggle the LEDs must be configured before you can use the setPinOutput functions.

Example: gpio_configurePin(0, LED, GPIO_OUTPUT_ENABLE | GPIO_INPUT_DISABLE, 1);

Give that a shot, if it's not the problem we can isolate it to the interrupt configuration and go from there.

Jacob

0 Likes
Anonymous
Not applicable

Hello, your interrupt handler function is wrong : void interrupt_gpio(void*)

It has too few arguments.

It should be: void interrupt_gpio(void *parameter, UINT8 arg)


Hope that helped.


James

0 Likes
Anonymous
Not applicable

Thanks, this allowed me to compile the code . even though both by interrupts, external and on board button are firing they it seems that every time the external interrupt occurs the one for the on board button is also being handled, I'm assuming this is because they are on the same port, if I'm correct is there a way to handle interrupts according to pins and not ports? The module also seems to crash and become unresponsive requiring a reboot since i started using the interrupt, any idea what could cause this? out of curiosity, how long did it take for some of you to get familiar with the module?

cheers

0 Likes

Here's an example using the PWM to toggle the LED: LED with PWM

0 Likes
Anonymous
Not applicable

Just curious, what module/board are you using?

0 Likes
Anonymous
Not applicable

I'm using the BCM20736S module from embeddedmasters (fdroberts2), I was asking so I can better estimate how long it might take me to implement solutions, I'm a recent graduate and most of my experience is on arduino, the MSP430 and some FPGAs. I got it working late last night after going through all the links provided here and reading related posts. After removing the on board button interrupt I realised the reason I was having issues was I wasn't setting up a second interrupt mask for my external button, seems dumb now but it wasn't made very clear in the hardware interfaces document that this was necessary, but the interrupt seems to fire twice though?. Thanks for all your help  

0 Likes
Anonymous
Not applicable

s.muyaba not quite sure what your problem is but

instead of

gpio_configurePin(0,dial,GPIO_EN_INT_RISING_EDGE|GPIO_PULL_DOWN,GPIO_PIN_INPUT_HIGH);

try:

gpio_configurePin(0, dial, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

0 Likes
Anonymous
Not applicable

s.muyaba sorry typo in my last response, please check response again, (gpio_configurePin(0, dial, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);)

0 Likes
Anonymous
Not applicable

Unfortunately that didn't work either, the interrupt is getting fired on both edge regardless of specifying an edge, is it possible that I maybe missed a configuration parameter to limit the interrupts to just one edge?

0 Likes
Anonymous
Not applicable

s.muyaba can you show us an updated snippet of your code?

0 Likes
Anonymous
Not applicable

My code hasn't changed, the only change I've made has been to the pin configuration

gpio_configurePin(0, dial, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

and this hasn't changed anything. I've made a temporary fix by checking that the pin is actually high and this works but I have concern about latency if the pin state was being toggled rapidly

0 Likes
Anonymous
Not applicable

have you taken a look at james's code? It works fine with his setup

We're having a hard time pinpointing where you are going wrong. 

0 Likes
Anonymous
Not applicable

I've sort of switched tasks atm but I'll be moving back to this next week and I'll update with any new changes

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hello.

When you are initializing the mask array, try changing the "or" statement to an assignment.

I did a quick demo app of what I think is what you are trying to do.

The external button will turn the external LED on and off, while the on-board button will do the same for the on-board LED.

Take a look at it for reference.

pastedImage_0.jpg

Please let us know if this solved your problem.

Thank you.

James