<?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>GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53286/gpiote-can-toggle-led-but-cannot-set-boolean</link><description>board: nRF52 DK 
 
 [update - fixed this - see #2] 
 When I use the following (shortened) code, the LED blinks when I press button 2 but I see no logs. NRF_LOG_INFO() is working in other areas of the code. 
 
 It doesn&amp;#39;t make sense to me that nrf_drv_gpiote_out_toggle</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Oct 2019 08:11:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53286/gpiote-can-toggle-led-but-cannot-set-boolean" /><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215649?ContentTypeID=1</link><pubDate>Fri, 18 Oct 2019 08:11:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2fd84e7-dceb-4b9c-854c-bc5a9a60c16f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user="mbards"]Still having the issue where when hx711_init() is called, pressing button 2 no longer triggers bma_tap_interrupt_handler(). When hx711_init() is commented out everything works fine[/quote]
&lt;p&gt;Could that be related to the NRF_GPIOTE-&amp;gt;CONFIG[1] call inside that function? That seems to overwrite your &amp;quot;LED1&amp;quot; configuration? You should check the pin and action, as mentioned earlier; if the pin pulse is very short, the handler will be called twice in a short time frame, and its likely that your program will not work as intended.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215600?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 18:42:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2677dbfe-8bee-468f-88d5-f40ad852d7ea</guid><dc:creator>mbards</dc:creator><description>&lt;p&gt;I added the fix to main after initialising both gpiote channels (using hx711_init and bma_enable_tap_interrupt)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define BMA_TAP_INTERRUPT_PIN BUTTON_2
bool foo = false;

void bma_tap_interrupt_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_drv_gpiote_out_toggle(LED1);
    foo = true;
}

void bma_enable_tap_interrupt(uint32_t pin, nrf_drv_gpiote_evt_handler_t evt_handler)
{
    ret_code_t ret_code;

    if (!nrf_drv_gpiote_is_init())
    {
        ret_code = nrf_drv_gpiote_init();
        APP_ERROR_CHECK(ret_code);
    }

    nrf_drv_gpiote_in_config_t gpiote_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    gpiote_config.pull = NRF_GPIO_PIN_PULLUP;

    ret_code = nrf_drv_gpiote_in_init(pin, &amp;amp;gpiote_config, evt_handler);
    APP_ERROR_CHECK(ret_code);

    nrf_drv_gpiote_in_event_enable(pin, true);

    NRF_LOG_INFO(&amp;quot;initialised pin %d for tap intr&amp;quot;, pin);

    /** for debug **/
    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    ret_code = nrf_drv_gpiote_out_init(LED1, &amp;amp;out_config);
    APP_ERROR_CHECK(ret_code);
    /** for debug **/
}

int main(void)
{
    hx711_init() // when this is commented out, the bma tap interrupt works
    bma_enable_tap_interrupt(BMA_TAP_INTERRUPT_PIN, bma_tap_interrupt_handler);
    
    /* Add fix for errata 155 */
    uint32_t GPIOTE_CH_USED = 0;
    uint32_t GPIOTE_CH_USED_1 = 1;
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * GPIOTE_CH_USED)) = 1;
    *(volatile uint32_t *)(NRF_GPIOTE_BASE + 0x600 + (4 * (GPIOTE_CH_USED_1))) = 1;

    for (;;)
    {
        if (foo)
        {
            NRF_LOG_INFO(&amp;quot;bar&amp;quot;);
            foo = false;
        }
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Still having the issue where when hx711_init() is called, pressing button 2 no longer triggers bma_tap_interrupt_handler(). When hx711_init() is commented out everything works fine&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215561?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2019 14:09:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:785b5694-5939-4873-b582-b3d1d8ce66c0</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is the issue that you read out incorrectly using this function, or is the initial issue with button 2 (GPIO P0.14) still present?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Did you try to implement the errata workaround? If you are sampling several channels asynchronously, you can still get into this scenario, even if the sampled signals are of lower frequency, as they can overlap with a very low time difference.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215372?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 18:07:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:925a4553-066f-4e94-aea5-f8e2e3ae2b00</guid><dc:creator>mbards</dc:creator><description>[quote userid="2115" url="~/f/nordic-q-a/53286/gpiote-can-toggle-led-but-cannot-set-boolean/215256"]&amp;nbsp;The channel is setup as a toggle, meaning that you get the handler called when it goes active and inactive, is that the intended behavior?[/quote]
&lt;p&gt;Just for debug. I will change it to LOTOHI/HITOLO when I&amp;#39;ve fixed the bug below.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/53286/gpiote-can-toggle-led-but-cannot-set-boolean/215256"]You are clearing and shutting down the timer when CC[2] hits. Do you start the timer again manually?[/quote]
&lt;p&gt;Yes I start the timer again in hx711_sample() using NRF_TIMER1-&amp;gt;TASKS_START = 1. To give you a sense of the code flow, I have an APP_TIMER setup to call hx711_start() every 2s. Then when dout goes low, gpiote clocks out the adc value using the sck pin&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void hx711_start()
{
    NRF_LOG_DEBUG(&amp;quot;start sampling&amp;quot;);
    
    NRF_GPIOTE-&amp;gt;TASKS_CLR[1] = 1;
    // Generates interrupt when new sampling is available. 
    nrf_drv_gpiote_in_event_enable(m_setup-&amp;gt;dout, true);
}

void hx711_stop()
{
    NRF_LOG_DEBUG(&amp;quot;stop sampling&amp;quot;);
    nrf_drv_gpiote_in_event_disable(m_setup-&amp;gt;dout);
}

/* Clocks out HX711 result - if readout fails consistently, try to increase the clock period and/or enable compiler optimization */
void hx711_sample()
{
    NRF_TIMER2-&amp;gt;TASKS_CLEAR = 1;
    m_sample.count = 0;
    m_sample.value = 0;
    m_sample.status = Busy;
    NRF_TIMER1-&amp;gt;TASKS_START = 1; // Starts clock signal on PD_SCK
    NRF_LOG_INFO(&amp;quot;sampling hx711&amp;quot;);

    for (uint32_t i=0; i &amp;lt; HX711_DEFAULT_ADC_RES; i++)
    {
        do
        {
            /* NRF_TIMER-&amp;gt;CC[1] contains number of clock cycles.*/
            NRF_TIMER2-&amp;gt;TASKS_CAPTURE[1] = 1;
            if (NRF_TIMER2-&amp;gt;CC[1] &amp;gt;= HX711_DEFAULT_ADC_RES)
            {
                NRF_LOG_WARNING(&amp;quot;readout not in sync&amp;quot;);
                goto EXIT; // Readout not in sync with PD_CLK. Abort and notify error.
            }
        }
        while(NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] == 0);
        NRF_TIMER1-&amp;gt;EVENTS_COMPARE[0] = 0;
        m_sample.value |= (nrf_gpio_pin_read(m_setup-&amp;gt;dout) &amp;lt;&amp;lt; (23 - i));
        m_sample.count++;
        m_sample.status = Unread;
    }
    EXIT:

    m_sample.value = hx711_convert(m_sample.value);
    
    if (m_sample.value &amp;gt; 0x7FFFFF)
    {
        NRF_LOG_WARNING(&amp;quot;sample returned a negative value. Check connections&amp;quot;);
        return;
    }
    NRF_LOG_DEBUG(&amp;quot;number of bits: %d. ADC val: 0x%x or 0d%d&amp;quot;, 
    m_sample.count,
    m_sample.value,
    m_sample.value);

    if (hx711_callback != NULL)
    {
        hx711_callback(&amp;amp;m_sample.value);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/53286/gpiote-can-toggle-led-but-cannot-set-boolean/215256"]Is the input signal in the MHz range? If so, you should look at implementing the workaround for this errata[/quote]
&lt;p&gt;My TIMER1 prescaler is set to 0, so my timer is running in the MHz. The input signal from the hx711 to the dout pin is at most 80 Hz.&lt;/p&gt;
&lt;p&gt;I checked to see which pins each GPIOTE was assigned to. GPIOTE[0] is pin 26 (dout) and GPIOTE[1] is pin 14 (button 2 in pca10040.h). So the channels appear to be separated. Still not sure what the source of my problem is.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215368?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 17:26:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1ba2672e-54de-4545-aee7-b306ae30e1a6</guid><dc:creator>mbards</dc:creator><description>&lt;p&gt;bool foo = false worked fine. The problem was something dumb.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Since the problem only occurs when hx711_init() is called, I just made sure the hx711 pins don&amp;#39;t overlap. I do not think this is the source of the problem&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215256?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 11:11:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b2b8b2d-b192-46a1-8c9a-07be191f928f</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]When I use the following (shortened) code, the LED blinks when I press button 2 but I see no logs. NRF_LOG_INFO() is working in other areas of the code.[/quote]
&lt;p&gt;&amp;nbsp;The channel is setup as a toggle, meaning that you get the handler called when it goes active and inactive, is that the intended behavior?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
[quote user=""]For an extra challenge, when I add the following function call to main (setup pins: sck=2, dout=26), LED1 turns on but pressing button 2 does not actuate the led anymore.[/quote]
&lt;p&gt;You are clearing and shutting down the timer when CC[2] hits. Do you start the timer again manually?&lt;/p&gt;
&lt;p&gt;Is the input signal in the MHz range? If so, you should look at implementing the workaround for this errata:&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_155.html?cp=3_1_1_0_1_41"&gt;https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_155.html?cp=3_1_1_0_1_41&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GPIOTE can toggle led but cannot set boolean</title><link>https://devzone.nordicsemi.com/thread/215209?ContentTypeID=1</link><pubDate>Wed, 16 Oct 2019 07:44:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14c2261c-93ff-4261-b594-318bd9451004</guid><dc:creator>BinderT</dc:creator><description>&lt;p&gt;Hi,&lt;br /&gt;&lt;br /&gt;Try setting the bool like this:&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static bool foo = false;
volatile bool foo = false;
volatile static bool foo = false;
&lt;/pre&gt;&lt;br /&gt;&lt;a href="https://stackoverflow.com/questions/46010403/static-volatile-vs-static-vs-volatile-in-c"&gt;&lt;br /&gt;More info&lt;/a&gt; on this.&lt;br /&gt;&lt;br /&gt;Can also be the the interrupt is firing to fast.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//place in ISR
nrf_drv_gpiote_in_event_enable(pin, false);

//place in main
nrf_drv_gpiote_in_event_enable(pin, true);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;For #2 check that the DK is not using these pins for something else.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>