<?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>I2C (TWI driver) Bus recovery</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71454/i2c-twi-driver-bus-recovery</link><description>Hi I&amp;#39;m wondering if anyone has any tips on implementing a I2C recovery sequence with NRFX 2.3.0 (as included with Zephyr 2.4.99). I&amp;#39;ve seen this discussed https://devzone.nordicsemi.com/f/nordic-q-a/33466/twi-clearing-bus-with-nrfx_twi-driver but I can</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 10 Feb 2021 00:44:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71454/i2c-twi-driver-bus-recovery" /><item><title>RE: I2C (TWI driver) Bus recovery</title><link>https://devzone.nordicsemi.com/thread/293654?ContentTypeID=1</link><pubDate>Wed, 10 Feb 2021 00:44:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22d95323-d8d8-405d-9202-2ce0d24e7831</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I took a look at&amp;nbsp;nRF5_SDK_17.0.2_d674dde\integration\nrfx\legacy\nrf_drv_twi.c--&amp;gt;twi_clear_bus() and it did the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void twi_clear_bus(nrf_drv_twi_config_t const * p_config)
{
    NRF_GPIO-&amp;gt;PIN_CNF[p_config-&amp;gt;scl] = SCL_PIN_INIT_CONF;
    NRF_GPIO-&amp;gt;PIN_CNF[p_config-&amp;gt;sda] = SDA_PIN_INIT_CONF;

    nrf_gpio_pin_set(p_config-&amp;gt;scl);
    nrf_gpio_pin_set(p_config-&amp;gt;sda);

    NRF_GPIO-&amp;gt;PIN_CNF[p_config-&amp;gt;scl] = SCL_PIN_INIT_CONF_CLR;
    NRF_GPIO-&amp;gt;PIN_CNF[p_config-&amp;gt;sda] = SDA_PIN_INIT_CONF_CLR;

    nrf_delay_us(4);

    for (int i = 0; i &amp;lt; 9; i++)
    {
        if (nrf_gpio_pin_read(p_config-&amp;gt;sda))
        {
            if (i == 0)
            {
                return;
            }
            else
            {
                break;
            }
        }
        nrf_gpio_pin_clear(p_config-&amp;gt;scl);
        nrf_delay_us(4);
        nrf_gpio_pin_set(p_config-&amp;gt;scl);
        nrf_delay_us(4);
    }
    nrf_gpio_pin_clear(p_config-&amp;gt;sda);
    nrf_delay_us(4);
    nrf_gpio_pin_set(p_config-&amp;gt;sda);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I could not find any similar functions in NCS/Zephyr, so if you want to use twi_clear_bus(), use the code above as a reference.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In the thread&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/21508/twi-stuck-bus-recovery"&gt;TWI Stuck Bus Recovery&lt;/a&gt;&amp;nbsp;it was recommended to&amp;nbsp;&lt;span&gt;reinitialize the I2C driver, however I&amp;#39;m not quite sure how to go about this if you&amp;#39;re using the Zephyr drivers, since you&amp;#39;re not running the init function yourself. It happens automatically before main. However, f you use the nrfx drivers directly, you will be able to reinitialize the driver, since you run the init function yourself.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Another solutions could be to reset the chip, which will reinitialize the I2C.&amp;nbsp;If the device you&amp;#39;re communicating with has a reset pin, you could solve it by triggering a reset on that chip as well.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>