<?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>TWI Slave Sample</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/115590/twi-slave-sample</link><description>I&amp;#39;m thinking of incorporating a TWI slave with nRF52832. 
 I&amp;#39;m using SDK 17.0.2. 
 I want to set up a register and read/write multiple bytes with TWI, but I don&amp;#39;t know how to write the twis_event_handler process. 
 Are there any good samples?</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Oct 2024 10:41:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/115590/twi-slave-sample" /><item><title>RE: TWI Slave Sample</title><link>https://devzone.nordicsemi.com/thread/507109?ContentTypeID=1</link><pubDate>Mon, 21 Oct 2024 10:41:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37d04dc3-5757-47de-9463-8ee8acdd7069</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could you try to&amp;nbsp;prepare&amp;nbsp;the data buffer earlier, in the NRFX_TWIS_EVT_WRITE_REQ phase,&amp;nbsp;irrespective of whether the register address has been received?&lt;/p&gt;
&lt;p&gt;You could also make sure that the &lt;em&gt;nrf_drv_twis_rx_prepare&lt;/em&gt;() is called quickly enough for the data phase.&lt;/p&gt;
&lt;p&gt;Because right now, if there’s a timing issue or race condition, the slave may not have the data buffer ready in time, causing the master to not receive an ACK for the data phase.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave Sample</title><link>https://devzone.nordicsemi.com/thread/506752?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2024 14:31:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:30a49c7a-c481-4cdc-9f93-c48549cbd151</guid><dc:creator>Junichi</dc:creator><description>&lt;p&gt;Thank you for the information.&lt;/p&gt;
&lt;p&gt;Currently, I can read from the master, but write operations don&amp;#39;t work properly because an NRFX_TWIS_EVT_GENERAL_ERROR occurs.&lt;/p&gt;
&lt;p&gt;When I look with a protocol analyzer, I can see that ACKs are returned up to the slave address and register address, but no ACK is returned for data, and in the slave event, I can read the register address but not the data.&lt;/p&gt;
&lt;p&gt;What do you think is the cause?&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attached the source code for the current event handler.&lt;pre class="ui-code" data-mode="text"&gt;void twis_event_handler(nrf_drv_twis_evt_t const * p_event)
{
     static bool address_received = false; 

    switch (p_event-&amp;gt;type)
    {
        case NRFX_TWIS_EVT_READ_REQ:
            nrf_drv_twis_tx_prepare(&amp;amp;m_twis, &amp;amp;m_twi_register[m_register_address], TWI_BUFFER_SIZE - m_register_address);
            NRF_LOG_INFO(&amp;quot;Read request: register address = 0x%02X&amp;quot;, m_register_address);
            break;

        case NRFX_TWIS_EVT_WRITE_REQ:
            if (!address_received) {
                NRF_LOG_INFO(&amp;quot;Preparing to receive register address...&amp;quot;);
                nrf_drv_twis_rx_prepare(&amp;amp;m_twis, &amp;amp;m_register_address, 1);
            } else {
                NRF_LOG_INFO(&amp;quot;Register address received: 0x%02X&amp;quot;, m_register_address);
                if (m_register_address &amp;lt; TWI_BUFFER_SIZE) {
                    NRF_LOG_INFO(&amp;quot;Preparing to write data to register 0x%02X&amp;quot;, m_register_address);
                    nrf_drv_twis_rx_prepare(&amp;amp;m_twis, &amp;amp;m_twi_register[m_register_address], TWI_BUFFER_SIZE - m_register_address);
                } else {
                    NRF_LOG_ERROR(&amp;quot;Invalid register address: 0x%02X&amp;quot;, m_register_address);
                }
            }
            break;

        case NRFX_TWIS_EVT_WRITE_DONE:
            if (!address_received) {
                address_received = true;
                NRF_LOG_INFO(&amp;quot;Register address 0x%02X received&amp;quot;, m_register_address);
            } else {
                address_received = false;
                NRF_LOG_INFO(&amp;quot;Data written to register 0x%02X: 0x%02X&amp;quot;, m_register_address, m_twi_register[m_register_address]);
            }
            break;

        case NRFX_TWIS_EVT_READ_DONE:
            NRF_LOG_INFO(&amp;quot;Read completed&amp;quot;);
            break;

        case NRFX_TWIS_EVT_READ_ERROR:
            NRF_LOG_ERROR(&amp;quot;TWIS EVT READ ERROR&amp;quot;);
            break;

        case NRFX_TWIS_EVT_WRITE_ERROR:
            NRF_LOG_ERROR(&amp;quot;TWIS EVT WRITE ERROR&amp;quot;);
            break;
        
        case NRFX_TWIS_EVT_GENERAL_ERROR:
            NRF_LOG_ERROR(&amp;quot;TWIS EVT GENERAL ERROR&amp;quot;);
            break;

        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Slave Sample</title><link>https://devzone.nordicsemi.com/thread/506717?ContentTypeID=1</link><pubDate>Thu, 17 Oct 2024 12:23:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42b1ea1c-420b-4b38-a2fa-f8d9480e8121</guid><dc:creator>Priyanka</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Please take a look at the &lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/group_nrfx_twis.html"&gt;TWIS driver&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;There is also a sample implementation&amp;nbsp;mentioned here:&amp;nbsp;&lt;a href="https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/hardware_driver_twis_slave.html#twi_slave_asynchronous_mode:~:text=void%20twis_event_handler(nrf_drv_twis_evt_t%20const%20*%20const%20p_event)"&gt;https://docs.nordicsemi.com/bundle/sdk_nrf5_v17.1.0/page/hardware_driver_twis_slave.html#twi_slave_asynchronous_mode:~:text=void%20twis_event_handler(nrf_drv_twis_evt_t%20const%20*%20const%20p_event)&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please also take a look at the TWIS implementation guide:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/peripherals/posts/twi-ic2-implementation-with-nrfx-twis-driver#mcetoc_1fc9idhsd3"&gt;https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/peripherals/posts/twi-ic2-implementation-with-nrfx-twis-driver#mcetoc_1fc9idhsd3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Priyanka&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>