Use P1.04 as interruption in nrf5340

hello everyone, recently I entered the world of nordic, 
and I have been testing some of the functionalities, of one of the devices,
 specifically the nrf5304 dk model, I am trying to make a connection between a sensor and this model 
using gpio P1.04 as interrupted, however taking into account what I learned from the course,
I have not found a way to interact with the pin using the nordic sdk,
as I understand it seems to be possible to use the gpio linked to the buttons and leds,
but I would like to know if is it possible to use other pins and how to do the configuration process.
Again I would really appreciate your help.
Parents
  • P1.04 is oin 4 in GPIO1 port/peripheral.. This is generally what you could ... you may need to tweak it to compile/work for you

    const struct device *gpio_1_dev; //device struct for GPIO1
    static struct gpio_callback my_cb; //callback handle
    gpio_1_dev = device_get_binding("GPIO_1");
    
    if (!gpio_1_dev) {
    printk("\n!!!!!!!! Cannot get GPIO_1 device\n");
    return;
    } else {
    printk("\nGPIO_1 device binding SUCCESS\n");
    }
    
    //ocnfigure your pin for interrupt
    
    gpio_pin_configure(gpio_1_dev, 4, GPIO_INPUT);
    
    int ret = gpio_pin_interrupt_configure(gpio_1_dev, 4, GPIO_INT_EDGE_FALLING); // edge falling is just an example.. you should set it what you need it to be
    if (ret != 0) {
    printk("Error %d: failed to configure interrupt pin %d\n", ret, 4);
    return;
    }
    
    //set up call backs )(what to do once you get an interrupt)
    gpio_init_callback(&my_cb, my_intr_process, BIT(4));
    gpio_add_callback(gpio_1_dev, &my_cb);
    
    
    
    // and define your actual call back function which does whatever you need to do when interrupt does show up.. hint.. don;t do too many things here
    void my_intr_process(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    printk("\n\n my intr happened\n\n");
    
    //give semaphore or set a voltaile flag etc.
    }

Reply
  • P1.04 is oin 4 in GPIO1 port/peripheral.. This is generally what you could ... you may need to tweak it to compile/work for you

    const struct device *gpio_1_dev; //device struct for GPIO1
    static struct gpio_callback my_cb; //callback handle
    gpio_1_dev = device_get_binding("GPIO_1");
    
    if (!gpio_1_dev) {
    printk("\n!!!!!!!! Cannot get GPIO_1 device\n");
    return;
    } else {
    printk("\nGPIO_1 device binding SUCCESS\n");
    }
    
    //ocnfigure your pin for interrupt
    
    gpio_pin_configure(gpio_1_dev, 4, GPIO_INPUT);
    
    int ret = gpio_pin_interrupt_configure(gpio_1_dev, 4, GPIO_INT_EDGE_FALLING); // edge falling is just an example.. you should set it what you need it to be
    if (ret != 0) {
    printk("Error %d: failed to configure interrupt pin %d\n", ret, 4);
    return;
    }
    
    //set up call backs )(what to do once you get an interrupt)
    gpio_init_callback(&my_cb, my_intr_process, BIT(4));
    gpio_add_callback(gpio_1_dev, &my_cb);
    
    
    
    // and define your actual call back function which does whatever you need to do when interrupt does show up.. hint.. don;t do too many things here
    void my_intr_process(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
    printk("\n\n my intr happened\n\n");
    
    //give semaphore or set a voltaile flag etc.
    }

Children
No Data
Related