<?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>Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50442/slave-address-read-unexpectedly-in-twi</link><description>Hi, Everyone 
 I use sdk15.2 &amp;amp; nrf52832 
 I am doing a test to read the slave address in TWI
There is one slave device on the board and the slave address is 0x68 
I used three examples in twi_scanner, twi_sensor, twi_master_using_nrf_twi_mgnr
The slave</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 22 Oct 2019 07:40:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50442/slave-address-read-unexpectedly-in-twi" /><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/216068?ContentTypeID=1</link><pubDate>Tue, 22 Oct 2019 07:40:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4346f7ef-283e-4ebb-8a2b-8a488a134ef9</guid><dc:creator>alex kim</dc:creator><description>&lt;p&gt;&lt;span&gt;Sorry. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;There was a hardware mistake.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/202298?ContentTypeID=1</link><pubDate>Mon, 05 Aug 2019 06:17:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d15494db-0ddd-4a78-be43-ffb1208ef547</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I am having a bit of problem seeing how you do things in the second (non-working) case, where you use non-blocking transfers. Where do you print the &amp;quot;TWI device detected at address &lt;em&gt;xx&lt;/em&gt;&amp;quot; in that case? The code you have posted is just for the first case (which is working as expected from what I understand).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/202011?ContentTypeID=1</link><pubDate>Fri, 02 Aug 2019 00:54:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08a112fe-424d-4029-b12d-28e78a85113e</guid><dc:creator>alex kim</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nordic_common.h&amp;quot;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;ble_hci.h&amp;quot;
#include &amp;quot;ble_advdata.h&amp;quot;
#include &amp;quot;ble_advertising.h&amp;quot;
#include &amp;quot;ble_conn_params.h&amp;quot;
#include &amp;quot;nrf_sdh.h&amp;quot;
#include &amp;quot;nrf_sdh_soc.h&amp;quot;
#include &amp;quot;nrf_sdh_ble.h&amp;quot;
#include &amp;quot;nrf_ble_gatt.h&amp;quot;
#include &amp;quot;nrf_ble_qwr.h&amp;quot;
#include &amp;quot;app_timer.h&amp;quot;
#include &amp;quot;ble_nus.h&amp;quot;
#include &amp;quot;app_uart.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;bsp_btn_ble.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;

#if defined (UART_PRESENT)
#include &amp;quot;nrf_uart.h&amp;quot;
#endif
#if defined (UARTE_PRESENT)
#include &amp;quot;nrf_uarte.h&amp;quot;
#endif

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;

void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{
    switch (p_event-&amp;gt;type)
    {
        case NRF_DRV_TWI_EVT_DONE:
            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
//                data_handler(m_sample);
            }
            m_xfer_done = true;
            break;
        default:
            break;
    }
}

/**
 * @brief TWI initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_config = {
       .scl                = 16,		//ARDUINO_SCL_PIN,
       .sda                = 17,		//ARDUINO_SDA_PIN,
       .frequency          = NRF_DRV_TWI_FREQ_400K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL);
//    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, twi_handler, NULL);	
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);
}

int main(void)
{
    bool erase_bonds;

    // Initialize.
     uart_init();
	
    log_init();
    timers_init();
	cat_timers_init();
	saadc_init();
	
    twi_init();
	
	#define TWI_ADDRESSES	127
	ret_code_t err_code;
	uint8_t detected_device = 0;
	uint8_t sample_data;
    for (uint8_t address = 1; address &amp;lt;= TWI_ADDRESSES; address++)
    {
        err_code = nrf_drv_twi_rx(&amp;amp;m_twi, address, &amp;amp;sample_data, sizeof(sample_data));
        if (err_code == NRF_SUCCESS)
        {
            detected_device = true;
            NRF_LOG_INFO(&amp;quot;TWI device detected at address 0x%x.&amp;quot;, address);
        }
        NRF_LOG_FLUSH();
    }

    if (!detected_device)
    {
        NRF_LOG_INFO(&amp;quot;No device was found.&amp;quot;);
        NRF_LOG_FLUSH();
    }
    ICM20602_whoAmI();
	ICM20602_init();
	
    buttons_leds_init(&amp;amp;erase_bonds);
	gpio_led_init();	
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();

    // Start execution.
    NRF_LOG_INFO(&amp;quot;Debug logging for UART over RTT started.&amp;quot;);
    advertising_start();
	cat_timers_start();
	
    // Enter main loop.
    for (;;)
    {
        idle_state_handle();
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/201790?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 09:41:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1e75e690-4791-4c46-9363-4c5cd98fe6e6</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/6747._5F00_Insert-Code-_2D00_-Nordic-2.png" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/201707?ContentTypeID=1</link><pubDate>Thu, 01 Aug 2019 01:01:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f820c290-6127-4527-97b5-447aa8891e2f</guid><dc:creator>alex kim</dc:creator><description>&lt;p&gt;Hi, awneil&lt;/p&gt;
&lt;p&gt;1. &lt;span&gt;I used the following code to detect the TWI address of the Slave&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;for (address = 1; address &amp;lt;= TWI_ADDRESSES; address++)&lt;br /&gt; {&lt;br /&gt;&amp;nbsp; &amp;nbsp;err_code = nrf_drv_twi_rx(&amp;amp;m_twi, address, &amp;amp;sample_data, sizeof(sample_data));&lt;br /&gt;&amp;nbsp; &amp;nbsp;if (err_code == NRF_SUCCESS)&lt;br /&gt;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; detected_device = true;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; NRF_LOG_INFO(&amp;quot;TWI device detected at address 0x%x.&amp;quot;, address);&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;NRF_LOG_FLUSH();&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;2. &lt;span&gt;my scl and sda were connected to p16 and p17&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. twi_init()&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1) ret_code_t ret = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The slave address is&amp;nbsp;detected as 0x68. It is normal.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2)&amp;nbsp;ret_code_t ret = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, twi_handler, NULL);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp; &amp;nbsp;switch (p_event-&amp;gt;type)&lt;br /&gt;&amp;nbsp; {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;case NRF_DRV_TWI_EVT_DONE:&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data_handler(m_sample);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;m_xfer_done = true;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;&amp;nbsp; &amp;nbsp; default:&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;pre dir="ltr"&gt;0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x1.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x5.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x8.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0xB.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0xE.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x12.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x15.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x18.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x1B.&lt;br /&gt; 0&amp;gt; &amp;lt;info&amp;gt; app: TWI device detected at address 0x1E.&lt;br /&gt;&lt;br /&gt;&lt;span lang="en"&gt;&lt;span&gt;A strange slave address is detected.&lt;br /&gt;0x68 is not visible&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Best Regards,&lt;br /&gt;&lt;br /&gt;Alex&lt;/span&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Slave address read unexpectedly in TWI</title><link>https://devzone.nordicsemi.com/thread/201548?ContentTypeID=1</link><pubDate>Wed, 31 Jul 2019 11:47:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6a6c1a9-7d47-4233-aebb-5d3c433de2d8</guid><dc:creator>awneil</dc:creator><description>[quote userid="69031" url="~/f/nordic-q-a/50442/slave-address-read-unexpectedly-in-twi"]read the slave address in TWI[/quote]
&lt;p&gt;That doesn&amp;#39;t make sense!&lt;/p&gt;
&lt;p&gt;You don&amp;#39;t &lt;em&gt;&lt;strong&gt;read&lt;/strong&gt; &lt;/em&gt;the Slave Address in I2C (aka TWI).&lt;/p&gt;
&lt;p&gt;You &lt;em&gt;&lt;strong&gt;send&lt;/strong&gt; &lt;/em&gt;the Slave address to identify which slave should&amp;nbsp;respond.&lt;/p&gt;
&lt;p&gt;I think you need to review how I2C works:&lt;/p&gt;
&lt;p&gt;Here is the I2C Specification:&amp;nbsp;&lt;a href="https://www.nxp.com/docs/en/user-guide/UM10204.pdf"&gt;https://www.nxp.com/docs/en/user-guide/UM10204.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/I%C2%B2C"&gt;https://en.wikipedia.org/wiki/I%C2%B2C&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;etc, ...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>