This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to set gpioe to low accuracy in NCS

Excuse me:

                      I now use NCS to develop nrf52840 applications. My applications require IO events of more than 8 channels. How should I configure them.

Parents
  • You can add a GPIO input interrupt with a callback using the following code:

    #define PIN 23
    
    void button_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
        printk("Button pressed");
    }
    
    void main(void)
    {
        const struct device *gpio_dev;
        static struct gpio_callback button_cb_data;
        
        gpio_dev = device_get_binding("GPIO_0");
        gpio_pin_configure(gpio_dev, PIN, GPIO_INPUT | GPIO_PULL_UP);
        gpio_pin_interrupt_configure(gpio_dev, PIN, GPIO_INT_EDGE_TO_INACTIVE);
        gpio_init_callback(&button_cb_data, button_callback, BIT(PIN));
        gpio_add_callback(gpio_dev, &button_cb_data);
    }

    To use GPIOTE PORT event instead of GPIOTE IN event, add the following to prj.conf:

    CONFIG_GPIO_NRF_INT_EDGE_USING_SENSE=y

Reply
  • You can add a GPIO input interrupt with a callback using the following code:

    #define PIN 23
    
    void button_callback(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
        printk("Button pressed");
    }
    
    void main(void)
    {
        const struct device *gpio_dev;
        static struct gpio_callback button_cb_data;
        
        gpio_dev = device_get_binding("GPIO_0");
        gpio_pin_configure(gpio_dev, PIN, GPIO_INPUT | GPIO_PULL_UP);
        gpio_pin_interrupt_configure(gpio_dev, PIN, GPIO_INT_EDGE_TO_INACTIVE);
        gpio_init_callback(&button_cb_data, button_callback, BIT(PIN));
        gpio_add_callback(gpio_dev, &button_cb_data);
    }

    To use GPIOTE PORT event instead of GPIOTE IN event, add the following to prj.conf:

    CONFIG_GPIO_NRF_INT_EDGE_USING_SENSE=y

Children
No Data
Related