<?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>Softdevice - how to get twi / i2c address from twi_handler</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/110921/softdevice---how-to-get-twi-i2c-address-from-twi_handler</link><description>Hello All, 
 I am using nRF SDK 17.0.2 (softdevice). I have connected multiple sensors using I2C protocol, I want to know if there is any failure in sensor and if it is not responding on twi then I am getting event NRF_DRV_TWI_EVT_ADDRESS_NACK but how</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 07 May 2024 07:54:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/110921/softdevice---how-to-get-twi-i2c-address-from-twi_handler" /><item><title>RE: Softdevice - how to get twi / i2c address from twi_handler</title><link>https://devzone.nordicsemi.com/thread/482188?ContentTypeID=1</link><pubDate>Tue, 07 May 2024 07:54:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2e0e52a5-68d7-486a-9024-90b379634ba5</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Neeraj,&lt;/p&gt;
&lt;p&gt;Not directly. The context is provided by&amp;nbsp;nrf_drv_twi_init(), and not&amp;nbsp;nrf_drv_twi_xfer(), so not for each transaction. You could of course provide a pointer to a variable and update that same variable before every call to&amp;nbsp;nrf_drv_twi_xfer(), but that would not give you any benefits compared to using a global variable (it would just make things a bit more complicated).&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Softdevice - how to get twi / i2c address from twi_handler</title><link>https://devzone.nordicsemi.com/thread/482162?ContentTypeID=1</link><pubDate>Tue, 07 May 2024 06:22:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef019a44-b3d9-462a-a775-f4cb10020f5c</guid><dc:creator>Neeraj Dhekale</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/eith"&gt;Einar Thorsrud&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;Got it your logic using&amp;nbsp;&lt;span&gt;&lt;strong&gt;current_address&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
[quote userid="7377" url="~/f/nordic-q-a/110921/softdevice---how-to-get-twi-i2c-address-from-twi_handler/482074"]The &lt;code&gt;p_context&lt;/code&gt; is a void pointer that you can use to pass extra information to the event handler,[/quote]
&lt;p&gt;Any chance to pass i2c address to p_context as extra information? if yes, how can I implement it?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks and regards,&lt;/p&gt;
&lt;p&gt;Neeraj Dhekale&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Softdevice - how to get twi / i2c address from twi_handler</title><link>https://devzone.nordicsemi.com/thread/482074?ContentTypeID=1</link><pubDate>Mon, 06 May 2024 14:09:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47f3abd2-bf6e-4b6e-9b2a-59520a374957</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;NRF_DRV_TWI_EVT_ADDRESS_NACK&lt;/code&gt; event is triggered when the slave device does not acknowledge its address. However, the &lt;code&gt;p_context&lt;/code&gt; does not hold the address of the non-acknowledging device. The &lt;code&gt;p_context&lt;/code&gt; is a void pointer that you can use to pass extra information to the event handler, but it&amp;#39;s not automatically filled with any specific data by the TWI driver.&lt;/p&gt;
&lt;p&gt;To identify which device is not acknowledging its address, you could modify your code to store the address of the device you&amp;#39;re currently trying to communicate with in a global variable. Then, in your event handler, you can check this global variable when you receive the &lt;code&gt;NRF_DRV_TWI_EVT_ADDRESS_NACK&lt;/code&gt; event.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t current_address;

void twi_event_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_TWI_EVT_ADDRESS_NACK:
            printf(&amp;quot;No ACK from device with address: 0x%x\n&amp;quot;, current_address);
            break;
        // Handle other events...
    }
}

void communicate_with_device(uint8_t address)
{
    current_address = address;
    // Start communication...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this example, before you start communicating with a device, you store its address in &lt;code&gt;current_address&lt;/code&gt;. Then, if you receive a &lt;code&gt;NRF_DRV_TWI_EVT_ADDRESS_NACK&lt;/code&gt; event, you know that &lt;code&gt;current_address&lt;/code&gt; is the address of the device that didn&amp;#39;t acknowledge its address.&lt;/p&gt;
&lt;p&gt;Please note that this is a simple example and might not cover all your needs. For example, if you&amp;#39;re communicating with multiple devices simultaneously from different threads, you&amp;#39;ll need a more sophisticated way to track which address corresponds to which NACK event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>