<?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 can&amp;#39;t read data from sensor</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59271/twi-can-t-read-data-from-sensor</link><description>Hi, 
 example : nRF5_SDK_15.0.0_a53641a\examples\peripheral\twi_sensor 
 I am using the HTU21D sensor. I was download the twi_scanner example to scan the HTU21D sensor&amp;#39;s slave address. the others sensors can be sanned. But the HTU21D can&amp;#39;t be scanned</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 23 Mar 2020 13:21:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59271/twi-can-t-read-data-from-sensor" /><item><title>RE: twi can't read data from sensor</title><link>https://devzone.nordicsemi.com/thread/241145?ContentTypeID=1</link><pubDate>Mon, 23 Mar 2020 13:21:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bfe50ea6-04f1-4415-a500-9e2fcfe81380</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Can you share a scope of the SDA and SCL lines?&amp;nbsp;&lt;/p&gt;
[quote user="lisi"]that you need to retry at a later point.&amp;nbsp;[/quote]
&lt;p&gt;&amp;nbsp;It means that the driver is busy with the last transaction and that you need to wait until the last transaction has completed until you can issue another one.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: twi can't read data from sensor</title><link>https://devzone.nordicsemi.com/thread/240887?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2020 13:31:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90fe58c5-af1c-4ac7-a410-5d0ea63272e3</guid><dc:creator>lisi</dc:creator><description>&lt;p&gt;&lt;span&gt;I used an oscilloscope to grab the waveform of the SCL line, and there was no waveform change after the application reported an NRF_ERROR_BUSY error. I debug found that the applocation is stop at&amp;nbsp;while (m_xfer_done == false);&lt;/span&gt;&lt;/p&gt;
[quote userid="13562" url="~/f/nordic-q-a/59271/twi-can-t-read-data-from-sensor/240850"] that you need to retry at a later point.&amp;nbsp;[/quote]
&lt;p&gt;Sorry, I didn&amp;#39;t understand what that meant&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: twi can't read data from sensor</title><link>https://devzone.nordicsemi.com/thread/240850?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2020 12:05:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fce2607-4c2c-4b58-8af5-f67a0a10c6c6</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;NRF_ERROR_BUSY means that the TWI peripheral is still in a transaction and that you need to retry at a later point.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="lisi"]I use oscilloscope, at first there is level conversion, then there is no.[/quote]
&lt;p&gt;&amp;nbsp;I do not know what that means, can you share a scope of the TWI lines?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: twi can't read data from sensor</title><link>https://devzone.nordicsemi.com/thread/240814?ContentTypeID=1</link><pubDate>Fri, 20 Mar 2020 10:27:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4265ff28-80b0-4bdd-956f-1bd969377e88</guid><dc:creator>lisi</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I use oscilloscope, at first there is level conversion, then there is no.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I used analog I2c could&amp;nbsp;&amp;nbsp;add the delay function after sent/written the read address by the master.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt; Below is the main.c file&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;
/** @file
 * @defgroup tw_sensor_example main.c
 * @{
 * @ingroup nrf_twi_example
 * @brief TWI Sensor Example main file.
 *
 * This file contains the source code for a sample application using TWI.
 *
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;


#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;

/* TWI instance ID. */
#define TWI_INSTANCE_ID     0

/* Common addresses definition for temperature sensor. */

#define        HTU21D_SlaveAddress   (0x80U&amp;gt;&amp;gt;1)          //&amp;#182;&amp;#168;&amp;#210;&amp;#229;HTU21D&amp;#212;&amp;#218;I2C&amp;#215;&amp;#220;&amp;#207;&amp;#223;&amp;#201;&amp;#207;&amp;#181;&amp;#196;&amp;#180;&amp;#211;&amp;#181;&amp;#216;&amp;#214;&amp;#183;

/* Mode for LM75B. */
#define NORMAL_MODE 0U

/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;

/* TWI instance. */
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

/* Buffer for samples read from temperature sensor. */
static uint8_t m_sample;

/**
 * @brief Function for handling data from temperature sensor.
 *
 * @param[in] temp          Temperature in Celsius degrees read from sensor.
 */
__STATIC_INLINE void data_handler(uint8_t temp)
{
    NRF_LOG_INFO(&amp;quot;Value: 0x%x .&amp;quot;, temp);
}

/**
 * @brief TWI events handler.
 */
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 UART initialization.
 */
void twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_lm75b_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_DRV_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_lm75b_config, twi_handler, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);
}

void HTU21D_sensor_init()
{
		//reset sensor
		ret_code_t err_code;
		m_xfer_done=false;
    uint8_t reg[1] = {0xfe};
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, HTU21D_SlaveAddress, reg, sizeof(reg), false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
}

void read_data_reg(uint8_t regAddr)
{
		ret_code_t err_code;
		uint8_t reg[1] = {regAddr};
    m_xfer_done = false;
    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, HTU21D_SlaveAddress, reg, 1, false);
    APP_ERROR_CHECK(err_code);
    while (m_xfer_done == false);
		
		m_xfer_done = false;
    /* Read 1 byte from the specified address - skip 3 bits dedicated for fractional part of temperature. */
    err_code = nrf_drv_twi_rx(&amp;amp;m_twi, HTU21D_SlaveAddress, &amp;amp;m_sample, sizeof(m_sample));
    APP_ERROR_CHECK(err_code);
		
}

int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO(&amp;quot;\r\nTWI sensor example started.&amp;quot;);
    NRF_LOG_FLUSH();
	
    twi_init();
		HTU21D_sensor_init();
		read_data_reg(0xE7);  //read user register
		
    while (true)
    {
        nrf_delay_ms(500);
				
				read_data_reg(0xE3);  //read Temperature  register LSB
				read_data_reg(0xE3+1);  //read Temperature  register MSB
			
				NRF_LOG_FLUSH();
    }
}

/** @} */
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Below is the log file&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Value: 0x2 .
&amp;lt;error&amp;gt; app: ERROR 17 [NRF_ERROR_BUSY] at ..\..\..\main.c:110
PC at: 0x000021A5
&amp;lt;error&amp;gt; app: End of error report
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I sincerely look forward to your reply. thanks&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: twi can't read data from sensor</title><link>https://devzone.nordicsemi.com/thread/240666?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2020 14:13:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:055b22d4-258c-4bc9-9b41-4d231c4df81f</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;We need a scope from a digital analyzer in order to know what&amp;#39;s going on.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;The holding/delay seems to be controlled by the slave, not the master.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>