GPIO interrupt for DRDY pin in NCS 2.5.2

I wrote a code for GPIO interrupt when DRDY pin goes high to low(Data ready) interrupt should occur and call a function but it is not working 

Below is a code:

intDRDY = false;

#define GPIO_DRDY 8

#define GPIO1 DT_NODELABEL(gpio1)

const struct device *gpio1_dev = DEVICE_DT_GET(GPIO1);

static struct gpio_callback gpio_cb;

/*call back function */

static void gpio_callback(const struct device *dev,

                         struct gpio_callback *cb,

                         uint32_t pins)

{

     intDRDY = true; 

}

in main function i am calling that function 

gpio_pin_configure(gpio1_dev, GPIO_DRDY, GPIO_INPUT);

 gpio_pin_interrupt_configure(gpio1_dev, GPIO_DRDY, GPIO_INT_EDGE_FALLING);

gpio_init_callback(&gpio_cb, gpio_callback, BIT(GPIO_DRDY));

gpio_add_callback(gpio1_dev, &gpio_cb);

while(1)

{

             if(intDRDY)

          {

              intDRDY = false;

              ADS_RDATA();

         }

}


it is not working 

Is there a way to occur interrupt in different way or i did any mistake

Thank you in advance

  • Hi,

     

    You have to declare intDRDY as volatile.

    Here's a setup that worked on my side (added a pull-down for simplicity):

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <stdio.h>
    #include <zephyr/kernel.h>
    #include <zephyr/drivers/gpio.h>
    #include <hal/nrf_gpio.h>
    
    volatile bool intDRDY = false;
    #define GPIO_DRDY 8
    #define GPIO1 DT_NODELABEL(gpio1)
    const struct device *gpio1_dev = DEVICE_DT_GET(GPIO1);
    static struct gpio_callback gpio_cb;
    
    /*call back function */
    
    static void gpio_handler(const struct device *dev,
                             struct gpio_callback *cb,
                             uint32_t pins)
    
    {
         intDRDY = true;	 
    }
    
    
    int main(void) 
    {
    	if (!device_is_ready(gpio1_dev)) {
    		printk("Device not ready\n");
    	}
    	int ret = gpio_pin_configure(gpio1_dev, GPIO_DRDY, GPIO_INPUT | GPIO_PULL_DOWN);
    	printk("Ret %d\n", ret);
    	ret = gpio_pin_interrupt_configure(gpio1_dev, GPIO_DRDY, GPIO_INT_EDGE_FALLING);
    	printk("Ret %d\n", ret);
    	gpio_init_callback(&gpio_cb, gpio_handler, BIT(GPIO_DRDY));
    	printk("Ret %d\n", ret);
    	ret = gpio_add_callback(gpio1_dev, &gpio_cb);
    	printk("Ret %d\n", ret);
    	nrf_gpio_cfg_output(13);
    	while(1)
    	{
    		if(intDRDY)
    		{
    			intDRDY = false;
    			nrf_gpio_pin_toggle(13);
    		}
    	}
    }

     

    Kind regards,

    Håkon

  • Happy to help out. Hope you have a great day!

     

    Kind regards,

    Håkon

Related