<?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>nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94330/nrf52832-how-to-toggle-two-synced-pulsing-gpio-pins-between-input-high-impedance-and-output</link><description>Description: 
 I have two GPIO pins whose polarity is toggled via PPI signal. These pins are pulsing in sync: both are simultaneously high, and simultaneously low. I&amp;#39;d like to toggle between these two pins so that only one is in use at a time (output</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 15 Dec 2022 08:18:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94330/nrf52832-how-to-toggle-two-synced-pulsing-gpio-pins-between-input-high-impedance-and-output" /><item><title>RE: nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/thread/400754?ContentTypeID=1</link><pubDate>Thu, 15 Dec 2022 08:18:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ddd8854-13e9-4a06-afc9-5eccb1a4d9d1</guid><dc:creator>ISH</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;good news! I reached my goal and got the pins&amp;#39; directions to change. It&amp;#39;s a bit embarrassing to admit, but the cause of the problem was the way I triggered the callback. Basically, the way I got to test the high-z was to apply a 2-divisible cycle to ensure the pulse had both rising and falling edge. Although this is not the situation I want to end up with, it&amp;#39;s an issue I have to solve later. The original problem with the pins&amp;#39; direction is solved. Here&amp;#39;s the callback function that did the trick:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void callback(bool ok)
{
...
...
    nrf_gpiote_task_disable(NRF_GPIOTE, ch_inactive);     // this releases the GPIOTE from the GPIO
    nrf_gpio_cfg_input(p_inactive, NRF_GPIO_PIN_NOPULL);  // now we can adjust the GPIO&amp;#39;s PIN_CNF
    nrf_gpio_cfg_output(p_active);
    nrf_gpiote_task_enable(NRF_GPIOTE, ch_active);
...
...
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/thread/400391?ContentTypeID=1</link><pubDate>Tue, 13 Dec 2022 13:23:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31b64300-7a23-4f59-8691-1863bf5b13d1</guid><dc:creator>ISH</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;sorry for the late response. I&amp;#39;ve been trying everything I could come up with based on your suggestions. Unfortunately I still haven&amp;#39;t been able to solve this issue. Reading back to the original post I feel like I haven&amp;#39;t been clear enough with the program structure, so please let me try to elaborate.&lt;/p&gt;
&lt;p&gt;In the PPI-module the RTC event that triggers the GPIOTE TOGGLE task also triggers an SAADC task that reads a value. This triggers a callback function, which evaluates the result and calls the GPIOTE function that is responsible for the switching between the direction of these two pins. So this switching happens in the CPU.&lt;/p&gt;
&lt;p&gt;The goal is that the POLARITY.TOGGLE register would change the pin&amp;#39;s polarity even though the pin itself is an input. And the effect would take place once the pin is switched back to output direction.&lt;/p&gt;
&lt;p&gt;To make the demonstrations easier to understand, I&amp;#39;ll try to toggle only one pin instead of two like in the OP. This is what I&amp;#39;ve tried in the callback function since your last post:&lt;/p&gt;
&lt;p&gt;Direct register writing to GPIO pin configuration:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static nrfx_gpiote_pin_t pin = DT_GPIO_PIN(DT_NODELABEL(mm_gpio0), gpios);

void callback(bool set_in)
{
    static NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&amp;amp;pin);
    
    if (set_in) {
        reg-&amp;gt;PIN_CFG[pin] = (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos) |
                            (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos) |
                            (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos) |
                            (GPIO_PIN_CNF_DRIVE_S0S1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) |
                            (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos);
    } else {
        reg-&amp;gt;PIN_CFG[pin] = (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos) |
                            (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos) |
                            (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos) |
                            (GPIO_PIN_CNF_DRIVE_S0S1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos) |
                            (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;or more dynamic way:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static nrfx_gpiote_pin_t pin = DT_GPIO_PIN(DT_NODELABEL(mm_gpio0), gpios);

void callback(bool set_in)
{
    NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&amp;amp;pin);
    uint32_t cur_cfg = reg-&amp;gt;PIN_CNF[pin];           // get pin&amp;#39;s configuration
    cur_cfg &amp;amp;= ~(GPIO_PIN_CNF_DIR_Msk);             // clear direction register
    
    if (set_in) {
        cur_cfg |= (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
    } else {
        cur_cfg |= (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
    }
    
    reg-&amp;gt;PIN_CNF[pin] = cur_cfg;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also tried to affect the GPIOTE module registers, specifically CONFIG[n].MODE. The documentation says that if the mode is switched to Event, it switches the GPIO&amp;#39;s PIN_CNF[n].DIR to Input, MODE.Task switches the DIR to Output and MODE.Disabled enables the CNF[n] of the GPIO pin, disconnecting the GPIOTE module from the pin.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static uint8_t ch;    // this has been allocated by using nrfx_gpiote_channel_alloc(&amp;amp;ch)

void callback(bool set_in)
{
    uin32_t cur_cfg;
    cur_cfg = NRF_GPIOTE-&amp;gt;CONFIG[ch];
    cur_cfg &amp;amp;= ~(GPIOTE_CONFIG_MODE_Msk);
    
    if (set_in) {
        cur_cfg |= (GPIOTE_CONFIG_MODE_Disabled &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
        
        // Also tried this
        //cur_cfg |= (GPIOTE_CONFIG_MODE_Event &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
    } else {
        cur_cfg |= (GPIOTE_CONFIG_MODE_Task &amp;lt;&amp;lt; GPIOTE_CONFIG_MODE_Pos);
    }

    NRF_GPIOTE-&amp;gt;CONFIG[ch] = cur_cfg;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;nrfx_gpiote.h library functions:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void callback(bool set_in)
{
    if (set_in) {
        nrfx_gpiote_out_task_disable(pin);
    } else {
        nrfx_gpiote_out_task_enable(pin);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;None of these methods worked. The result was a flatline, the pin is not set. I hope I managed to explain the situation better, but if not, please let me know if I could provide some more information. Any suggestions on how to try to solve the issue?&lt;/p&gt;
&lt;p&gt;Thank you for your help.&lt;/p&gt;
&lt;p&gt;EDIT: I read the GPIO register after changing the GPIOTE MODE, and the register content didn&amp;#39;t change. I don&amp;#39;t know if I should see the changes in DIR? But also at the same time writing to GPIO&amp;#39;s DIR does change the register values, but doesn&amp;#39;t show on the oscilloscope as pulsing. The pin is still flatlining.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/thread/399422?ContentTypeID=1</link><pubDate>Wed, 07 Dec 2022 13:10:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba4bd0d2-4b07-468f-a4dd-4cc2b67d3d81</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The PIN_CFG will not hold the previous value is you write a new config. If you want to set multiple fields, you either need to write the second value with &amp;quot;|=&amp;quot;, or bitwise or the values before assigning:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_GPIO-&amp;gt;PIN_CNF[nonactive] =  (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
NRF_GPIO-&amp;gt;PIN_CNF[nonactive] |= (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos);

// OR:
NRF_GPIO-&amp;gt;PIN_CNF[nonactive] = (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos) |
                               (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos);&lt;/pre&gt;In this particular case, it should not matter though, as DIR_Input is the reset value (0) of the field in this register.&lt;/p&gt;
[quote user="ISH"] hoping to see any kind of effect like a flatline.[/quote]
&lt;p&gt;What do you mean by this? If the pin is configured as high impedance, the pin would be floating, not tied to zero.&lt;/p&gt;
[quote user="ISH"]&lt;p&gt;Might this be the reason (from the documents):&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:979.372px;" dir="ltr"&gt;As long as a SET[n], CLR[n] and OUT[n] task or an IN[n] event is configured to control a pin&lt;/span&gt;&lt;span style="font-family:sans-serif;left:769.82px;top:979.372px;" dir="ltr"&gt; &lt;/span&gt;&lt;span style="font-family:sans-serif;left:774.453px;top:979.372px;" dir="ltr"&gt;n&lt;/span&gt;&lt;span style="font-family:sans-serif;left:784.637px;top:979.372px;" dir="ltr"&gt;, the pin&amp;#39;s &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:999.372px;" dir="ltr"&gt;output value will only be updated by the GPIOTE module. The pin&amp;#39;s output value as specified in the GPIO will &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1019.37px;" dir="ltr"&gt;therefore be ignored as long as the pin is controlled by GPIOTE. &lt;strong&gt;Attempting to write a pin as a normal GPIO &lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1039.37px;" dir="ltr"&gt;&lt;strong&gt;pin will have no effect.&lt;/strong&gt; When the GPIOTE is disconnected from a pin, see MODE field in CONFIG[n] register, &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1059.37px;" dir="ltr"&gt;the associated pin will get the output and configuration values specified in the GPIO module.&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;As far as I know, the GPIO configuration (drive strength, pull resistors, etc) should still be applied to the pin, even though it is controlled by the GPIOTE, you will just not be able to control the value of the pin. GPIO configuration functions are used by the GPIOTE driver to set configs like &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/v1.9.0/drivers/src/nrfx_gpiote.c#L357-L364"&gt;initial output value&lt;/a&gt;, and &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/v1.9.0/drivers/src/nrfx_gpiote.c#L574"&gt;pull resistor configs&lt;/a&gt;.&lt;/p&gt;
[quote user="ISH"]There is a mention of disconnecting GPIOTE from the GPIO before writing. Would this be a solution? I don&amp;#39;t know how to do this other than using something like &lt;strong&gt;nrfx_gpiote_pin_uninit()&lt;/strong&gt;. This seems to lead a reconfiguration cycle, since I would need to configure the pin as output everytime a switch is done. This seems a bit messy way to do it.[/quote]
&lt;p&gt;I think the most suitable API that the driver provides would be &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/v1.9.0/drivers/src/nrfx_gpiote.c#L376"&gt;nrfx_gpiote_out_uninit&lt;/a&gt;&lt;span&gt;(). It would also technically be possible to clear the PSEL field of the GPIOTE-&amp;gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpiote.html?cp=4_2_0_20_3_2#register.CONFIG-0"&gt;CONFIG[n]&lt;/a&gt;&amp;nbsp;register, but then you might cause issues for the driver if you do not restore it properly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/thread/398492?ContentTypeID=1</link><pubDate>Thu, 01 Dec 2022 10:00:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d61d543-fdc1-4072-865f-d769ec0ed994</guid><dc:creator>ISH</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;thank you for the suggestion.&lt;/p&gt;
&lt;p&gt;I tried as such:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_GPIO-&amp;gt;PIN_CNF[nonactive] = (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
NRF_GPIO-&amp;gt;PIN_CNF[nonactive] = (GPIO_PIN_CNF_INPUT_Disconnect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos);
//NRF_GPIO-&amp;gt;PIN_CNF[active] = (GPIO_PIN_CNF_DIR_Output &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I tried both with and without the output configuration, hoping to see any kind of effect like a flatline. However these configurations seem to do nothing as is. Might this be the reason (from the documents):&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:979.372px;" dir="ltr"&gt;As long as a SET[n], CLR[n] and OUT[n] task or an IN[n] event is configured to control a pin&lt;/span&gt;&lt;span style="font-family:sans-serif;left:769.82px;top:979.372px;" dir="ltr"&gt; &lt;/span&gt;&lt;span style="font-family:sans-serif;left:774.453px;top:979.372px;" dir="ltr"&gt;n&lt;/span&gt;&lt;span style="font-family:sans-serif;left:784.637px;top:979.372px;" dir="ltr"&gt;, the pin&amp;#39;s &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:999.372px;" dir="ltr"&gt;output value will only be updated by the GPIOTE module. The pin&amp;#39;s output value as specified in the GPIO will &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1019.37px;" dir="ltr"&gt;therefore be ignored as long as the pin is controlled by GPIOTE. &lt;strong&gt;Attempting to write a pin as a normal GPIO &lt;/strong&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1039.37px;" dir="ltr"&gt;&lt;strong&gt;pin will have no effect.&lt;/strong&gt; When the GPIOTE is disconnected from a pin, see MODE field in CONFIG[n] register, &lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1059.37px;" dir="ltr"&gt;the associated pin will get the output and configuration values specified in the GPIO module.&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:inherit;"&gt;&lt;em&gt;&lt;span style="font-family:sans-serif;left:94.4867px;top:1059.37px;" dir="ltr"&gt;...&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span dir="ltr"&gt;Or maybe I have other registers to toggle that I have overlooked? I haven&amp;#39;t worked like this with registers too much yet.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span dir="ltr"&gt;There is a mention of disconnecting GPIOTE from the GPIO before writing. Would this be a solution? I don&amp;#39;t know how to do this other than using something like &lt;strong&gt;nrfx_gpiote_pin_uninit()&lt;/strong&gt;. This seems to lead a reconfiguration cycle, since I would need to configure the pin as output everytime a switch is done. This seems a bit messy way to do it.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span dir="ltr"&gt;Do you have any further thoughts or suggestions?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832: how to toggle two synced pulsing GPIO pins between input (high impedance) and output</title><link>https://devzone.nordicsemi.com/thread/398391?ContentTypeID=1</link><pubDate>Wed, 30 Nov 2022 15:55:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02298021-e438-4e2c-8691-f408b059cb2a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you tried to set the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpio.html?cp=4_2_0_19_2_9#register.PIN_CNF-0"&gt;PIN_CNF&lt;/a&gt;-&amp;gt;DIR to &amp;quot;Input&amp;quot; and&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/gpio.html?cp=4_2_0_19_2_9#register.PIN_CNF-0"&gt;PIN_CNF&lt;/a&gt;-&amp;gt;&lt;span&gt;INPUT to &amp;quot;Disconnect&amp;quot; for the nonactive pin?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>