<?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 demo code on nRF51-DK resets</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/11904/twi-demo-code-on-nrf51-dk-resets</link><description>I&amp;#39;m testing out twi_master_using_app_twi example code on the nRF51-DK. 
 It appears to wite on the twi bus as expected but the nRF51 resets after executing 
 // Initialize sensors.
APP_ERROR_CHECK(app_twi_perform(&amp;amp;m_app_twi, lm75b_init_transfers, LM75B_INIT_TRANSFER_COUNT</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 16 Feb 2016 13:23:26 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/11904/twi-demo-code-on-nrf51-dk-resets" /><item><title>RE: TWI demo code on nRF51-DK resets</title><link>https://devzone.nordicsemi.com/thread/45104?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2016 13:23:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f742f76f-3db2-490c-b822-56ddde532bfa</guid><dc:creator>ypearson</dc:creator><description>&lt;p&gt;Thanks for the link!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI demo code on nRF51-DK resets</title><link>https://devzone.nordicsemi.com/thread/45106?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2016 13:22:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63460e0c-04e7-4712-8321-894733cbd8c4</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Thank you for posting the solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI demo code on nRF51-DK resets</title><link>https://devzone.nordicsemi.com/thread/45105?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2016 13:13:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59d18ee2-07a6-4955-950a-5517dfa74a6b</guid><dc:creator>ypearson</dc:creator><description>&lt;p&gt;I think I discovered the problem.&lt;/p&gt;
&lt;p&gt;nrf_drv_config.h needs to be edited &lt;strong&gt;even if&lt;/strong&gt; you provide a config to nrf_drv_twi_init()&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define TWI0_ENABLED 1

#if (TWI0_ENABLED == 1)
#define TWI0_CONFIG_FREQUENCY    NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL          24
#define TWI0_CONFIG_SDA          25
#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW

#define TWI0_INSTANCE_INDEX      0
#endif
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since in nrf_drv_twi.c there is the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#if (TWI0_ENABLED == 1)
void SPI0_TWI0_IRQHandler(void)
{
    nrf_drv_twi_int_handler(NRF_TWI0, TWI0_INSTANCE_INDEX);
}
#endif // (TWI0_ENABLED == 1)

#if (TWI1_ENABLED == 1)
void SPI1_TWI1_IRQHandler(void)
{
    nrf_drv_twi_int_handler(NRF_TWI1, TWI1_INSTANCE_INDEX);
}
#endif // (TWI1_ENABLED == 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It would appear that an interrupt handler would not exist otherwise, and depending on the startup code the nRF51 may then be lost in space.&lt;/p&gt;
&lt;p&gt;With those changes in place, this seems to do the right thing:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#include &amp;quot;app_twi.h&amp;quot;
#include &amp;quot;twi.h&amp;quot;
#include &amp;quot;nrf_drv_config.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;

static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(0);

void twi_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_twi_init(&amp;amp;m_twi, 0, 0, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(&amp;amp;m_twi);

    uint8_t reg[] = {0,0};

    err_code = nrf_drv_twi_tx(&amp;amp;m_twi, 0x70, reg, 1, true);
    err_code = nrf_drv_twi_rx(&amp;amp;m_twi, 0x70, reg, sizeof(reg), false);
    APP_ERROR_CHECK(err_code);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I&amp;#39;m using SDK v10 + s110&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/twi1.png" alt="image description" /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI demo code on nRF51-DK resets</title><link>https://devzone.nordicsemi.com/thread/45103?ContentTypeID=1</link><pubDate>Tue, 16 Feb 2016 10:34:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9fa98cf1-4bdc-437d-afde-086ffa456de9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;If your device resets after the line you posted, this is likely because &lt;code&gt;app_twi_perform()&lt;/code&gt; returned an error code. If you define &lt;code&gt;DEBUG&lt;/code&gt; in your project or Makefile, your device should instead enter a eternal loop in the &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v11.0.0%2Fgroup__app__error.html&amp;amp;anchor=gad8b5b293dfa06cbbfeb03aaaaa2772cf"&gt;&lt;code&gt;app_error_handler()&lt;/code&gt;&lt;/a&gt;. Using a debugger you can retrieve the error code which may indicate what has gone wrong.&lt;/p&gt;
&lt;p&gt;(The &lt;a href="https://devzone.nordicsemi.com/blogs/821/an-introduction-to-error-handling-in-nrf5-projects/"&gt;introduction to error handling in nRF5 projects&lt;/a&gt; is worth a read if you are inexperienced in debugging Nordic&amp;#39;s products.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>