<?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>I2C write function error.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/24822/i2c-write-function-error</link><description>Hello,
I am trying to interface bme280 with pca10040. I am using sdk12.2.2 and referring twi_sensor.
I am able to make read function and it works as expected. I am facing some challenge in write function. My write function doesnt give me error but it</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 01 Sep 2017 06:58:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/24822/i2c-write-function-error" /><item><title>RE: I2C write function error.</title><link>https://devzone.nordicsemi.com/thread/97725?ContentTypeID=1</link><pubDate>Fri, 01 Sep 2017 06:58:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cda9065e-2977-4b95-b6b8-7f702eb90bec</guid><dc:creator>Newbie</dc:creator><description>&lt;p&gt;Hi Martin,
My modified write function is as follows:&lt;/p&gt;
&lt;p&gt;ret_code_t write(uint8_t address, uint8_t reg, uint8_t value)
{
ret_code_t ret_code;
uint8_t data[2];
data[0] = reg;
data[1] = value;&lt;/p&gt;
&lt;p&gt;ret_code = nrf_drv_twi_tx(&amp;amp;m_twi,address, data, 2, false);
printf(&amp;quot;ret_c0de %d&amp;quot;, ret_code);
return ret_code;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;In my main I am calling as:
write(0x76, 0xF4, 0x01);&lt;/p&gt;
&lt;p&gt;I am printing the ret_code and its giving me 0 integer value.
Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C write function error.</title><link>https://devzone.nordicsemi.com/thread/97724?ContentTypeID=1</link><pubDate>Fri, 01 Sep 2017 06:40:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33d9a093-66d6-4ee8-9a93-332c35828354</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Where in the attached code are you checking the return value? After you initialize the TWI you call write_sensor_data() which in turn calls nrf_drv_twi_tx() and stores the return code in ret_code. But I can&amp;#39;t see that you are checking ret_code anywhere.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C write function error.</title><link>https://devzone.nordicsemi.com/thread/97726?ContentTypeID=1</link><pubDate>Fri, 01 Sep 2017 06:18:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ced3c7bc-442f-4dd2-bfb5-d3f4d31c97c3</guid><dc:creator>Newbie</dc:creator><description>&lt;p&gt;Hello Martin,
I checked return value of nrf_drv_twi_tx and I am getting 0. I think 0 means success. Can you suggest me code snippet of write function or can you modify my code snippet for write function?
Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C write function error.</title><link>https://devzone.nordicsemi.com/thread/97727?ContentTypeID=1</link><pubDate>Thu, 31 Aug 2017 14:42:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4bb1ae25-1022-4da6-b744-98b8d47f2ce1</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Are you sure you are not getting any errors? You are not checking the return value of nrf_drv_twi_tx() anywhere in your code? You should also check for *_NACK events in your twi_handler().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>