<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50471/how-to-configure-multiple-gpios-in-nrf9160-dk</link><description>I want to use several GPIOs for different purposes. 
 for example, - motion detection interrupt by accelerometer - low battery alert interrupt by battery gauge. 
 However, it doesn&amp;#39;t work. Any help? 
 This is my code below. When I configure second GPIO</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 01 Aug 2019 10:59:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50471/how-to-configure-multiple-gpios-in-nrf9160-dk" /><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201817?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 10:59:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1fbdcda-0e58-43a1-a0c4-c25796e95743</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;Glad to hear it &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201815?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 10:56:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fea6590-a780-41b1-a068-f8f4454d25a6</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;I confirmed it works. Thank you!!!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201797?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 09:56:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d3778c45-ec58-478f-9e38-77dbf2d542f2</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;seems ok, just tested two interrupt callbacks and they work&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201718?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 03:47:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a6ec138-0117-44b4-9145-8afa9990f949</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;Hi, MJD093.&lt;/p&gt;
&lt;p&gt;I improved the program using two GPIO interrupt. Is this correct?&lt;/p&gt;
&lt;p&gt;In the function of&amp;nbsp;init_accel_interrupt_gpio, the two GPIO interrupt is configured.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
#include &amp;lt;gpio.h&amp;gt;
#include &amp;lt;i2c.h&amp;gt;
#include &amp;lt;device.h&amp;gt;

/* for accelerometer */
#define I2C_ACCEL_ADDR (0x32 &amp;gt;&amp;gt; 1)
#define GPIO_IN_ACCEL_INT GPIO_OUT_PIN11_Pos
#define GPIO_IN_FAKE_INT GPIO_OUT_PIN18_Pos
#define DEV &amp;quot;dev&amp;quot;

struct device *i2c_accel;
struct device *gpio_accel_interrupt;
struct gpio_callback gpio_cb;
bool is_move = false;

struct device *gpio_fake_interrupt;
struct gpio_callback gpio_fake_cb;

void accel_interrupt(struct device *gpio, struct gpio_callback *cb, u32_t pins) {
    is_move = true;
}

void fake_interrupt(struct device *gpio, struct gpio_callback *cb, u32_t pins) {
    printk(&amp;quot;fake_interrupt\r\n&amp;quot;);
}

u8_t init_accelerometer() {
    i2c_accel = device_get_binding(&amp;quot;I2C_1&amp;quot;);
    if (!i2c_accel) {
        return -1;
    }

    /* Configure accelerometer */
    .
    .
    /* end */

    return 0;
}

u8_t init_accel_interrupt_gpio() {
    int8_t ret;

    gpio_cntrler = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
    if (!gpio_cntrler) {
        printk(&amp;quot;gpio_cntrler init error\r\n&amp;quot;);
        return -1;
    }
    
    /* accel_interrupt set up */
    
    ret = gpio_pin_configure(gpio_cntrler, GPIO_IN_ACCEL_INT, (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH));
    if (ret) {
        printk(&amp;quot;Error configuring %lu!\n&amp;quot;, GPIO_IN_ACCEL_INT);
        return -1;
    }
    
    gpio_init_callback(&amp;amp;gpio_cb, accel_interrupt, BIT(GPIO_IN_ACCEL_INT));

    ret = gpio_add_callback(gpio_cntrler, &amp;amp;gpio_cb);
    if (ret){
        printk(&amp;quot;Cannot setup callback!\n&amp;quot;);
        return -1;
    }

    ret =  gpio_pin_enable_callback(gpio_cntrler, GPIO_IN_ACCEL_INT);
    if (ret){
        printk(&amp;quot;Error enabling callback!\n&amp;quot;);
        return -1;
    }
    
    /* gpio_fake_interrupt */

    ret = gpio_pin_configure(gpio_cntrler, GPIO_IN_FAKE_INT, (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INT_ACTIVE_HIGH));
    if (ret) {
        printk(&amp;quot;Error configuring %lu!\n&amp;quot;, GPIO_IN_FAKE_INT);
        return -1;
    }

    gpio_init_callback(&amp;amp;gpio_fake_cb, fake_interrupt, BIT(GPIO_IN_FAKE_INT));

    ret = gpio_add_callback(gpio_cntrler, &amp;amp;gpio_fake_cb);
    if (ret){
        printk(&amp;quot;Cannot setup callback!\n&amp;quot;);
        return -1;
    }

    ret =  gpio_pin_enable_callback(gpio_cntrler, GPIO_IN_FAKE_INT);
    if (ret){
        printk(&amp;quot;Error enabling callback!\n&amp;quot;);
        return -1;
    }

    return 0;
}

void main(void)
{
    if(init_accelerometer() != 0) {
        sys_reboot();
    }

    if (init_accel_interrupt_gpio() != 0) {
        sys_reboot();
    }

    while (1) {
        k_cpu_idle();
        printk(&amp;quot;is_move = %u\n&amp;quot;, is_move);    
    }            
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201677?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 16:11:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb3fbef7-dab0-4b15-a692-aa3571d5deec</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;There shouldn&amp;#39;t be any issue with using gpio_callback again in main.c or in other source files. gpio_callback simply sets up a struct of type gpio_callback.&lt;/p&gt;
&lt;p&gt;You then link that structure to the struct device you set-up to hold the device_get_binding and gpio_pin_configure, using the callback functions. The APIs should allow you to set-up multiple callbacks this way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201676?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 16:00:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:234145cc-56cf-42bf-a7f7-b5cda665948a</guid><dc:creator>Yusuke</dc:creator><description>&lt;p&gt;Thank you for your reply!&lt;/p&gt;
&lt;p&gt;I got it. What about gpio_callback? Should it be only one object in main.c?&lt;/p&gt;
&lt;p&gt;Could you show me an example code which configures two different GPIO interrupt?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to configure multiple GPIOs in nRF9160 DK?</title><link>https://devzone.nordicsemi.com/thread/201670?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 15:43:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f77de9f3-f851-4c7d-a6be-1c69a07130b8</guid><dc:creator>MJD093</dc:creator><description>&lt;p&gt;GPIO_0 is the Pin Controller, all pins are controlled by GPIO_0. This includes all switches and LEDs on the pca10090.&lt;/p&gt;
&lt;p&gt;Your interrupt pin must also be controlled by GPIO_0. You do not number it as GPIO_#, it will always be GPIO_0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>