7 Replies Latest reply on Feb 16, 2016 2:23 PM by userc_19497

    BCM20737S External interrupt/ GPIO push button

      Hello,

       

      I am using the BCM20737S in a custom design.

       

      I want to set up a push button trigger an action.

       

      Currently I have my push button set up on P27. When the button is not pressed, it is open and is pulled to ground. When the button is pressed it is closed and pull to 2.8v.

       

      What do I need to do to set this up in software to trigger an event? Is there an example I can mess around with? I am currently using hello_sensor example.

       

      Regards,

      Luke.

        • 1. Re: BCM20737S External interrupt/ GPIO push button
          JacobT_81

          The code below will register for an interrupt on pin 0 (generally in create function or upon init of your sensor):

           

                   UINT16 masks[3] = {(1 << 0), 0 , 0};

                   gpio_registerForInterrupt(masks, interrupt_handler, 0);

                   gpio_configurePin(0, 0, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

           

          On every rising edge interrupt of pin 0, the following function will be called:

           

                   void interrupt_handler(void* parameter, UINT8 arg) {

                           /*your code here*/

                    }

           

          See the following post for how to alter the mask to register for interrupts on a different pin:

                    gpio_registerForInterrupt

           

          Jacob

          • 2. Re: BCM20737S External interrupt/ GPIO push button

            I had a go at this. A few problems came up.

             

            I want to fire an interrupt on the rising edge of p27. When the button is not pressed it is pulled to ground. When I press the button it is pulled to 2.8v, which is where my rising edge should be detected. Here is a schematic of my circuit:

             

            This is my mask:

             

            masks[3] = {0, (1<<11) , 0};

             

             

            Does this seem correct for p27?

             

            Also when I try to download the software I get an error that "interrupt_handler" is not declared.

             

            Inside in "interrupt_handler(void* parameter, UINT8 arg)" I just have software to display something on a display unit. This is not been displayed when I press the button so I presume I am not getting into here.

             

            Can you help? The code you gave seems basic, is there other bits that need to be setup that I am missing.

             

            Regards,

            Luke.

             

             

            • 3. Re: BCM20737S External interrupt/ GPIO push button

              It looks like you are getting a build error that "interrupt_handler" is not declared?

               

              If that is the case make sure you are declaring this function in your application header file

               

              This is your own private implementation and not something from the global space

              • 4. Re: BCM20737S External interrupt/ GPIO push button

                at the moment I am declaring my mask at the top of my c file:

                UINT16 masks[3] = {(0,1<<11, 0}; //p27

                 

                inside in my sensor create function I call:

                   gpio_registerForInterrupt(masks, interrupt_handler, 0);

                         gpio_configurePin(0, 0, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

                 

                And I then declare a function called:

                 

                void interrupt_handler(void* parameter, UINT8 arg) {

                                 //turn on led

                          }

                 

                 

                My question is, is my gpio_configurationPin been done correctly for p27.

                 

                Can anyone spot anything else wrong?

                • 5. Re: BCM20737S External interrupt/ GPIO push button
                  JacobT_81

                  Are you declaring your function at the top of the .c file or in the .h?

                   

                  static void interrupt_handler(void* parameter, UINT8 arg);

                   

                  As nasac_2167841 said, this appears to be a compiler error caused by no function declaration.

                   

                  Jacob

                  • 6. Re: BCM20737S External interrupt/ GPIO push button

                    I might not have done that!

                     

                    Is is my mask right for p27 ?

                     

                    Also is my gpio configura correct for p27

                    • 7. Re: BCM20737S External interrupt/ GPIO push button

                      Yes your mask seems to be correct. Remember just do (pin# % 16) with the right port.

                      port 0 : pin0~15

                      port 1 : pin16~31

                      port 2 : pin32~39

                       

                      but your gpio configuration is wrong.

                        gpio_configurePin(0, 0, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

                       

                      it should instead be:

                        gpio_configurePin( pin/16, pin%16, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

                      or

                      gpio_configurePin( 1, 11, GPIO_EN_INT_RISING_EDGE, GPIO_PIN_OUTPUT_LOW);

                       

                      the former is recommended for better programming style.

                       

                      James