Hi,
I'm modifying the Nodric Developer Academy example for GPIO (https://github.com/NordicDeveloperAcademy/ncs-fund/blob/main/v2.x.x/lesson2/fund_less2_exer2_solution/src/main.c), using the nRF52840DK.
I'm trying to trigger an interrupt based on high pin level, using the following code:
/* * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/drivers/gpio.h> /* 1000 msec = 1 sec */ #define SLEEP_TIME_MS 1000 /* The devicetree node identifier for the "led0" alias. */ #define LED0_NODE DT_ALIAS(led0) #define BUTTON0_NODE DT_NODELABEL(button0) #define BUTTON1_NODE DT_NODELABEL(button1) #define BUTTON2_NODE DT_NODELABEL(button2) //#define BUTTON_PORT DEVICE_DT_GET(DT_GPIO_CTLR(DT_NODELABEL(button0), gpios)) /* * A build error on this line means your board is unsupported. * See the sample documentation for information on how to fix this. */ static const struct gpio_dt_spec led0_spec = GPIO_DT_SPEC_GET(LED0_NODE, gpios); static const struct gpio_dt_spec button0_spec = GPIO_DT_SPEC_GET(BUTTON0_NODE, gpios); static const struct gpio_dt_spec button1_spec = GPIO_DT_SPEC_GET(BUTTON1_NODE, gpios); static const struct gpio_dt_spec button2_spec = GPIO_DT_SPEC_GET(BUTTON2_NODE, gpios); //Structure for GPIO callback when we define an interrupt static struct gpio_callback button2_cb; void button_pressed_callback(const struct device *gpiob, struct gpio_callback *cb, gpio_port_pins_t pins) { gpio_pin_toggle_dt(&led0_spec); gpio_pin_set_dt(&button1_spec, 1); } void main(void) { gpio_pin_configure_dt(&led0_spec, GPIO_OUTPUT); gpio_pin_configure_dt(&button0_spec, GPIO_INPUT | GPIO_ACTIVE_HIGH); gpio_pin_configure_dt(&button1_spec, GPIO_OUTPUT); gpio_pin_configure_dt(&button2_spec, GPIO_INPUT | GPIO_ACTIVE_HIGH); gpio_pin_interrupt_configure_dt(&button2_spec, GPIO_ACTIVE_HIGH); gpio_init_callback(&button2_cb, button_pressed_callback, BIT(button2_spec.pin)); gpio_add_callback(button2_spec.port, &button2_cb); while (1) { k_msleep(SLEEP_TIME_MS); } }
But button 2 (and the interrupt callback) will only work with a low level (triggered when connected to ground). How can I change this to active high (triggers when connected to VDD)?
Thanks in advance.