This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Interrupts on third-party board.

Hello!

I am currently working with Actinius' Icarus IoT board and I'm trying to get the interrupts to work. This is the boards' pin layout:

At the moment I have connected the 0 pin to a button and the 1 pin to a LED. My goal is to make the button trigger an interrupt that executes a function and turns on the LED light.
I have seen the blinky example and tried to modify it with little success.

I know that my "problem" is rather vague and is more a lack of skill and knowledge than a dysfunction with the board or the library. However, I cannot make it work and I would like just a pinpoint of where I have to start. Maybe I'm including the wrong library, using the wrong functions, or having the definitions all messed up. 

I appreciate your time and help, thank you in advance!


 

Parents
  • Hi,

    Have you taken a look at the button sample, found in the same folder as blinky? That shows how to use buttons with interrupts.

    You will likely also have to add an overlay file where you configure the pins as a button and a LED.

    Looking at the actinius_icarus board files, something like this should work:

    / {
        buttons {
            button1: button_1 {
                gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Push Button 2";
            };
        };
        
        leds {
    		button_led: led_3 {
    			gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
    			label = "Button LED";
    		};
    	};
    };

    Then you just combine the button and blinky samples, and modify the application to use the newly defined button and LED.

    If you run into any issues, let me know and I'll do my best to help.

  • This definitely helps, thank you! I also found the button sample you talked about, great help! However, I saw they are using a while loop for the interrupt. Is this necessary? If so, will this affect the power usage by a significant amount? My project currently tries to use as little power as possible so it can be run on solar power.

  • Hi again,

    I don't think it should be a big issue, but you just want to toggle the LED on a button press, right? In that case, you can probably remove the while loop and just handle the LED toggle in the button_pressed callback.

    Eventually you can look into entering system off mode, and having the interrupt as a wake-up source.

  • When using the example you gave me I keep getting this error in the "devicetree_unfixed.h":

    'DT_N_S_leds_S_led_3' undeclared (first use in this function); did you mean 'DT_N_S_leds_led_3_ORD'?
    Do you have any idea what causes this and how to fix it?

  • Hi again,

    I see that I forgot to add aliases. Try this:

    overlay:

    / {
        buttons {
            button1: button_1 {
                gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
                label = "Push Button 2";
            };
        };
        
        leds {
    		button_led: led_3 {
    			gpios = <&gpio0 1 GPIO_ACTIVE_LOW>;
    			label = "Button LED";
    		};
    	};
    
        aliases {
            led3 = &button_led;
    		sw1 = &button1;
    	};
    };

    main.c changes:

    /*
     * Get button configuration from the devicetree sw0 alias. This is mandatory.
     */
    #define SW1_NODE	DT_ALIAS(sw1)
    #if !DT_NODE_HAS_STATUS(SW1_NODE, okay)
    #error "Unsupported board: sw1 devicetree alias is not defined"
    #endif
    static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW1_NODE, gpios,
    							      {0});
    static struct gpio_callback button_cb_data;
    
    /*
     * The led0 devicetree alias is optional. If present, we'll use it
     * to turn on the LED whenever the button is pressed.
     */
    static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led3), gpios,
    						     {0});
    

    Let me know how that works.

  • Yes, you are correct, the alias was a part of the problem. However, I got the error while I was trying to define the button like this:

    #define BUTTON_NODE    		DT_NODELABEL(sw1)
    #define BUTTON_GPIO_LABEL	DT_GPIO_LABEL(BUTTON_NODE, gpios)
    #define BUTTON_GPIO_PIN		DT_GPIO_PIN(BUTTON_NODE, gpios)
    #define BUTTON_GPIO_FLAGS	GPIO_INPUT | DT_GPIO_FLAGS(BUTTON_NODE, gpios)

    but this got fixed when I change it to this:

    #define BUTTON_NODE    		DT_GPIO_PIN(DT_NODELABEL(sw1), gpios)
    #define BUTTON_GPIO_LABEL	DT_GPIO_LABEL(BUTTON_NODE, gpios)
    #define BUTTON_GPIO_FLAGS	GPIO_INPUT | DT_GPIO_FLAGS(BUTTON_NODE, gpios)
    

  • Everything works with the second implementation? I would expect the first one to work if DT_NODELABEL were changed to DT_ALIAS.

Reply Children
No Data
Related