<?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 in nrf51 SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10841/i2c-in-nrf51-sdk</link><description>I want to interface ADXl345 with nrf51 SDK. suppoose my device address is 0x53 and register address is 0x2D and i want to write value 8. now nordic i2c has function nrf_drv_twi_tx with attributes
nrf_drv_twi_t const *const p_instance,
uint8_t address</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 17 Jan 2019 15:28:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10841/i2c-in-nrf51-sdk" /><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/166308?ContentTypeID=1</link><pubDate>Thu, 17 Jan 2019 15:28:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de031d70-681c-4ec7-ba5c-4bcaa6838afe</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;OK, are you able to capture a logic trace of the SDA and SCL lines going to the&amp;nbsp;&lt;span&gt;ADXL345&amp;nbsp;?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/158949?ContentTypeID=1</link><pubDate>Mon, 26 Nov 2018 06:52:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:605dc1c6-9194-4a55-a2d2-b07089326846</guid><dc:creator>iamsheikhubaid</dc:creator><description>&lt;p&gt;Hello Bjorn-spockeli, I am waiting for your response.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/158532?ContentTypeID=1</link><pubDate>Thu, 22 Nov 2018 06:33:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2fb58d1-4085-4bf0-9db6-aae8ec563380</guid><dc:creator>iamsheikhubaid</dc:creator><description>&lt;p&gt;I am currently using nRF_SDK_15.2.0, also i am usinng PCA10056 because its for nRF52840-DK like PCA10059 is for nRF52 Dongle. I have nRF52840 development kit so i have chosen PCA10056, Isn&amp;#39;t it more or less similar with nRF52 DK, is there any main difference between nRF52 DK or nRF52840 DK? I just want to interface adxl-345 with my nRF52840 development kit using your library, but I am unable to get any values when I put these lines in the code.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;ADXL375_I2C_data_rate_set(0x0A);&lt;/span&gt;&lt;br /&gt;&lt;span&gt;ADXL375_I2C_offsets_set(0,0,0);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;also I have changed the SDA, SCL pins accordingly in TWI like&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;static ret_code_t twi_master_init(void)&lt;br /&gt;{&lt;br /&gt; ret_code_t ret;&lt;br /&gt; const nrf_drv_twi_config_t config =&lt;br /&gt; {&lt;br /&gt; .scl = TWI_SCL_M,&lt;br /&gt; .sda = TWI_SDA_M,&lt;br /&gt; .frequency = NRF_TWI_FREQ_400K,&lt;br /&gt; .interrupt_priority = APP_IRQ_PRIORITY_HIGH,&lt;br /&gt; .clear_bus_init = false&lt;br /&gt; };&lt;/p&gt;
&lt;p&gt;do&lt;br /&gt; {&lt;br /&gt; ret = nrf_drv_twi_init(&amp;amp;m_twi_master, &amp;amp;config, twi_handler, NULL);&lt;br /&gt; if(NRF_SUCCESS != ret)&lt;br /&gt; {&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt; nrf_drv_twi_enable(&amp;amp;m_twi_master);&lt;br /&gt; }while(0);&lt;br /&gt; return ret;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;where twi_handler is as&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)&lt;br /&gt;{&lt;br /&gt; switch (p_event-&amp;gt;type)&lt;br /&gt; {&lt;br /&gt; case NRF_DRV_TWI_EVT_DONE:&lt;br /&gt; if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)&lt;br /&gt; {&lt;br /&gt; ADXL375_I2C_acc_data_read(&amp;amp;x_val, &amp;amp;y_val, &amp;amp;z_val);&lt;br /&gt; }&lt;br /&gt; m_xfer_done = true;&lt;br /&gt; break;&lt;br /&gt; default:&lt;br /&gt; break;&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;also I have defined SDA SCL pins according to the development kit, in the header file as&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;#define TWI_SCL_M 27 //!&amp;lt; Master SCL pin&lt;/p&gt;
&lt;p&gt;#define TWI_SDA_M 26 //!&amp;lt; Master SDA pin&lt;br /&gt;#define MASTER_TWI_INST 0 //!&amp;lt; MASTERTWI interface&lt;/p&gt;
&lt;p&gt;/** I2C BUS ADRESSES*/&lt;br /&gt;#define ADXL375_ADDR 0x53&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;/** REGISTER ADDRESSES */&lt;br /&gt;#define DEVICE_ID 0x00&lt;br /&gt;#define OFSX 0x1E&lt;br /&gt;#define OFSY 0x1F&lt;br /&gt;#define OFSZ 0x20&lt;/p&gt;
&lt;p&gt;#define BW_RATE 0x2C&lt;br /&gt;#define POWER_CTL 0x2D&lt;br /&gt;#define DATAX0 0x32&lt;br /&gt;#define DATAY0 0x34&lt;br /&gt;#define DATAZ0 0x36&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But still I&amp;nbsp; am not getting&amp;nbsp; cann&amp;#39;t get any value. Can you help me out in this. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/158235?ContentTypeID=1</link><pubDate>Tue, 20 Nov 2018 15:42:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0a4a771-449a-4527-9cf6-781ae7fef698</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Why are you using a PCA10056(NRF52840 DK) Segger Embedded Studio project, when you state that you want to interface the&amp;nbsp;&lt;span&gt;ADXl345 with a nRF52 DK?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Also note that TWI driver used to make the&amp;nbsp;ADXl345 was made for a 3 year old SDK and may not be compatible with the SDK version you are using? WHich version is it? Is it SDK v15.0.0 or newer?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/158092?ContentTypeID=1</link><pubDate>Tue, 20 Nov 2018 06:03:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cfe52a1-e3c6-4652-85fb-19623cb9e6aa</guid><dc:creator>iamsheikhubaid</dc:creator><description>&lt;p&gt;I am running the code of twi sensor, where I have added the adxl part,&lt;/p&gt;
&lt;p&gt;here is the code of main&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;int main(void)&lt;br /&gt;{&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; uint16_t a;&lt;br /&gt;// nrf_delay_ms(1000);&lt;br /&gt; APP_ERROR_CHECK(NRF_LOG_INIT(NULL));&lt;br /&gt; NRF_LOG_DEFAULT_BACKENDS_INIT();&lt;br /&gt; ret_code_t ret_code;&lt;br /&gt; &lt;br /&gt; ret_code = twi_master_init();&lt;br /&gt; &lt;br /&gt; ADXL375_I2C_init(&amp;amp;m_twi_master);&lt;/p&gt;
&lt;p&gt;int16_t x_val;&lt;br /&gt; int16_t y_val;&lt;br /&gt; int16_t z_val;&lt;br /&gt; a=1;&lt;br /&gt; NRF_LOG_INFO(&amp;quot;A=%d&amp;quot;,a);&lt;/p&gt;
&lt;p&gt;ADXL375_I2C_data_rate_set(0x0A);&lt;br /&gt; ADXL375_I2C_offsets_set(0,0,0);&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; APP_ERROR_CHECK(ret_code);&lt;br /&gt; &lt;br /&gt; a=2;&lt;br /&gt; &lt;br /&gt; while (1)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;A=%d&amp;quot;,a);&lt;br /&gt; a=3;&lt;br /&gt; //NRF_LOG_INFO(&amp;quot;A=%d&amp;quot;,a);&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; ADXL375_I2C_acc_data_read(&amp;amp;x_val,&amp;amp;y_val,&amp;amp;z_val);&lt;br /&gt; NRF_LOG_INFO(&amp;quot;A=%d&amp;quot;,a);&lt;/p&gt;
&lt;p&gt;NRF_LOG_INFO(&amp;quot;x=%d, y=%d, z=%d&amp;quot;,x_val,y_val,z_val);&lt;br /&gt; //SEGGER_RTT_printf(0,&amp;quot;ACC DATA: X: %d Y: %d Z: %d \n&amp;quot;, x_val ,y_val, z_val);&lt;br /&gt; nrf_delay_ms(500);&lt;br /&gt; &lt;br /&gt; // Do nothing.&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;it will print A=1&lt;/p&gt;
&lt;p&gt;then comes a fatal error, here is the screen shot&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1542693595351v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Help me in this, Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/158023?ContentTypeID=1</link><pubDate>Mon, 19 Nov 2018 15:06:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7b0cb9d0-f58f-431b-8637-eaa3aca8b13b</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;The register map appears to be close to identical so i think it should work. Could you post the code you&amp;#39;re running and a screenshot of the call stack when you get the error?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/157998?ContentTypeID=1</link><pubDate>Mon, 19 Nov 2018 14:19:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a2a28865-c62f-45ea-a3a4-0d5f8a5ea4ed</guid><dc:creator>iamsheikhubaid</dc:creator><description>&lt;p&gt;I am trying to upload the code of&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/bjorn_2d00_spockeli"&gt;bjorn-spockeli&lt;/a&gt; to NRF52 DK, but the code will stuck into a Fatal Error at&amp;nbsp;these lines&lt;/p&gt;
&lt;p&gt;ADXL375_I2C_data_rate_set(0x0A);&lt;br /&gt; ADXL375_I2C_offsets_set(0,0,0);&lt;/p&gt;
&lt;p&gt;Can any body explain, will it work for adxl 345 or have to change the register values or configurations. Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40532?ContentTypeID=1</link><pubDate>Mon, 18 Jan 2016 13:51:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9913f3f7-e97f-40d3-9588-69a9db693bf4</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;how to do it&amp;gt;&amp;gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40531?ContentTypeID=1</link><pubDate>Mon, 18 Jan 2016 09:29:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b745a7e1-8c25-4381-a37a-8a54419d5998</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;@rushin: Can you mark this answer as correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40528?ContentTypeID=1</link><pubDate>Tue, 12 Jan 2016 13:23:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7557c3e1-e7df-49d0-ba33-ac0c01432e2b</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Yes, I have answered this in your other &lt;a href="https://devzone.nordicsemi.com/question/64033/check-external-interrupt-status/"&gt;question&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40530?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2016 15:38:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:62d5a091-231d-4159-a8a1-fd1b1a2dea63</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;can you help me in detecting single tap event??&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40529?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2016 15:38:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f808ae50-970a-4822-92aa-bafa2549c713</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;yes. it helped me lot. thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40527?ContentTypeID=1</link><pubDate>Mon, 11 Jan 2016 15:25:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d8673a68-97d0-45de-ba2b-211187eb8768</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;If this answered your question I would appreciate if you could accept the answer as correct.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40524?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2015 15:12:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db5b59d3-6cf1-41f7-9aaa-3b1d86462823</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;&lt;strong&gt;The ADXL375_I2C_data_rate_set()&lt;/strong&gt; is used to set the data rate,i.e how fast the ADXL345 is updating the measurements. The rate is by default set to 100Hz, please refer Table 7 and Table 19 in the &lt;a href="http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf"&gt;ADXL345 Datasheet&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The ADXL375_I2C_offsets_set()&lt;/strong&gt; writes the offsets values for the x, y and z axis measurements, please refer the OFSX, OFSY and OFSZ registers in the  &lt;a href="http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf"&gt;ADXL345 Datasheet&lt;/a&gt;. This function can be used to calibrate the accelerometer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40525?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2015 14:21:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67cbd6c8-66ba-4369-b01f-baab69ce0cb8</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;can you tell me purpose of this ADXL375_I2C_data_rate_set(),ADXL375_I2C_offsets_set() function?
without it i can also get data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40522?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2015 13:06:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:828c1cbd-3dd4-46d9-8107-27d3dce4881f</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;thanks its working&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40526?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2015 08:58:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14b34e50-8f12-4b7f-9eff-ffb13b52dc10</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Are you using RTT to print the data? Are you just getting zeroes or actual values?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40523?ContentTypeID=1</link><pubDate>Tue, 15 Dec 2015 15:55:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a177515-7ad9-41c4-985f-83d273b99740</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;it is giving me data. but my data is not changing&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40521?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 15:25:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31e2fa7f-eba2-4b1c-aede-c9879467bf19</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;thanks i will try it&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40520?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 15:20:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa8fb9a3-0dcd-411f-aff6-663ac7335ca2</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Rushin,&lt;/p&gt;
&lt;p&gt;you can take a look at the driver I wrote for the ADXL375. Its for the nRF52 SDK, but the twi_driver API should be close to identical with that of the nRF51 SDK.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/ADXL375_5F00_I2C.zip"&gt;ADXL375_I2C.zip&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40541?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 15:16:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78cf3b98-43d8-4d8f-a5ab-5a8730b5d554</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;it means i don&amp;#39;t require separate write function&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40540?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 15:15:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ad21066-4d4f-446b-b9d5-386f8995ab85</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;If you pass NULL as event handler you can do it the way you do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40539?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 15:10:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c968403-6303-4cba-a77c-7d5a0ac7f621</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;You need to wait for the transfer to finish before returning the data and the data array needs to be globally declared. For example the read data should be like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t tx_data[2];

uint16_t read_data(nrf_drv_twi_t const * const  m_twi_adxl_345,uint8_t i2cAddress, uint8_t reg) 
{

    uint32_t           err_code;
    uint8_t data[2] = {0, 0};
    uint8_t value;

    tx_done = false;
    //Use xfer_pending true for repeated start (no need to send start condition and address again)
    err_code = nrf_drv_twi_tx(m_twi_adxl_345,ADXL345_ADDR , data, sizeof(data), true);
    APP_ERROR_CHECK(err_code);
    
    while(tx_done == false);  //wait for TX transfer to be done
    rx_done = false;
    err_code =  nrf_drv_twi_rx(m_twi_adxl_345,ADXL345_ADDR,data,sizeof(data),false);
    APP_ERROR_CHECK(err_code);

    while(rx_done == false);  //wait for RX transfer to be done
    value = (data[0] &amp;lt;&amp;lt; 8) | data[1];
    return value;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is not efficient code as it busy-waits, but it should work. rx_done and tx_done should be set to true respectively in the twi_handler function.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40538?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 14:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:879610a5-de94-4c94-9dc8-2df132daea2e</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;ok may be i am not getting data because of it&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C in nrf51 SDK</title><link>https://devzone.nordicsemi.com/thread/40537?ContentTypeID=1</link><pubDate>Mon, 14 Dec 2015 14:55:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42f5898e-423b-4362-b274-600069f7f0d4</guid><dc:creator>rushin</dc:creator><description>&lt;p&gt;#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_uart.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define ARDUINO_I2C_SCL_PIN 7
#define ARDUINO_I2C_SDA_PIN 30

#define UART_TX_BUF_SIZE 256
#define UART_RX_BUF_SIZE 1
#define ADXL345_ADDR        0x53U
#define ADXL345_REG_MODE    0x2DU
#define ACTIVE_MODE 8u
#define NUMBER_OF_SAMPLES 20

static volatile bool m_set_mode_done;
static const nrf_drv_twi_t m_twi_adxl_345 = NRF_DRV_TWI_INSTANCE(0);

//uart
static void uart_events_handler(app_uart_evt_t * p_event)
{
    switch (p_event-&amp;gt;evt_type)
    {
        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event-&amp;gt;data.error_code);
            break;

        default:
            break;
    }
}
static void uart_config(void)
{
    uint32_t                     err_code;
    const app_uart_comm_params_t comm_params =
    {
        RX_PIN_NUMBER,
        TX_PIN_NUMBER,
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        APP_UART_FLOW_CONTROL_DISABLED,
        false,
        UART_BAUDRATE_BAUDRATE_Baud38400
    };

    APP_UART_FIFO_INIT(&amp;amp;comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_events_handler,
                       APP_IRQ_PRIORITY_LOW,
                       err_code);

    APP_ERROR_CHECK(err_code);
}


void ADXL345_set_mode(void)
{ret_code_t err_code;

	 uint8_t reg[2] = {ADXL345_REG_MODE, ACTIVE_MODE};
  err_code = nrf_drv_twi_tx(&amp;amp;m_twi_adxl_345,ADXL345_ADDR , reg, sizeof(reg), false);
	while(m_set_mode_done == false);
}
uint16_t read_data(nrf_drv_twi_t const * const  m_twi_adxl_345,uint8_t i2cAddress, uint8_t reg) 
{
 
uint32_t           err_code;
		uint8_t data[2] = {0, 0};
		uint8_t value;

          err_code = nrf_drv_twi_tx(m_twi_adxl_345,ADXL345_ADDR , data, sizeof(data), false);
          APP_ERROR_CHECK(err_code);
 err_code =  nrf_drv_twi_rx(m_twi_adxl_345,ADXL345_ADDR,data,sizeof(data),false);
                   
  value = (data[0] &amp;lt;&amp;lt; 8) | data[1];
    return value;
}


void write_data(nrf_drv_twi_t const * const  m_twi_adxl_345,uint8_t i2cAddress, uint8_t reg) {
    uint8_t tx_data[3];
uint32_t           err_code;
    tx_data[0] = (uint8_t)reg;

 
    err_code = nrf_drv_twi_tx(m_twi_adxl_345,ADXL345_ADDR , tx_data, sizeof(tx_data), false);
    APP_ERROR_CHECK(err_code);
}


void twi_init (void)
{
    ret_code_t err_code;
		const nrf_drv_twi_config_t twi_adxl_345_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH  // interrupt priority
};
	err_code = nrf_drv_twi_init(&amp;amp;m_twi_adxl_345, &amp;amp;twi_adxl_345_config, NULL, NULL);
    APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&amp;amp;m_twi_adxl_345);
}
int main(void)
{
    uart_config();
	uint8_t a;
   
    printf(&amp;quot;\n\rTWI sensor example\r\n&amp;quot;);
    twi_init();
    
    ADXL345_set_mode();
    write_data(&amp;amp;m_twi_adxl_345,ADXL345_ADDR,0x32);
	 a = read_data(&amp;amp;m_twi_adxl_345,ADXL345_ADDR,0x32);
	printf(&amp;quot;%d&amp;quot;,a);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;hey it is my finle code. but still not getting data&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>