<?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 starting</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/12573/twi-starting</link><description>Hello guys
I tried to start TWI bus and got a lot of questions. (NRF51 1422 AC) 
 I added necessary libraries, could You tell me what more i need to include in my code : 
 #define TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER (0U)
#define TWI_MASTER_CONFIG_DATA_PIN_NUMBER</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 21 Mar 2016 13:21:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/12573/twi-starting" /><item><title>RE: TWI starting</title><link>https://devzone.nordicsemi.com/thread/47751?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2016 13:21:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95db7b1c-f382-43b6-a695-8ef1d041d999</guid><dc:creator>MartinBL</dc:creator><description>&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If you use an event handler you are able to see what errors might occur and respond to these. If you don&amp;#39;t use an error handler and something goes wrong on your TWI bus you will end up in an endless loop. Your application will not work and you have no way of figuring out what is wrong.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the address is given as 00110101x in the datasheet then I would assume that your device address is actually 00110101 (0x35). The x represents the R/W bit and is not really a part of the address. So in this case you should pass 0x35 as the address to nrf_drv_twi_tx(). &lt;a href="https://github.com/Martinsbl/twi-find-devices-on-bus"&gt;Here&lt;/a&gt; is some example code that you can use to find your device&amp;#39;s address and debug your application.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;EDIT: Forgot to link to the examples.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI starting</title><link>https://devzone.nordicsemi.com/thread/47750?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2016 15:46:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cde414b5-c1d7-41a8-bcc5-255795d6ae36</guid><dc:creator>rago</dc:creator><description>&lt;p&gt;Thank You very much for answer !
I know Keil IDE, debugger is primary tool for me.
Anyway, could You explain me three more questions ?&lt;/p&gt;
&lt;p&gt;1st : While I&amp;#39;m sure with my code, using event hander in trasmission is necessary ?&lt;/p&gt;
&lt;p&gt;2nd : I know first frame of transmission is :&lt;/p&gt;
&lt;p&gt;(Adr)(Adr)(Adr)(Adr)(Adr)(Adr)(Adr)(R/W) where Adr are bytes of device adress&lt;/p&gt;
&lt;p&gt;In sdk is written :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;* @param[in] address    Address of a specific slave device **(only 7 LSB).**
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How to understand it ?&lt;/p&gt;
&lt;p&gt;In datasheet i have adress like 00110101x where last bit is not important.&lt;/p&gt;
&lt;p&gt;But input param need 7 LSB with adress then if I impart paramter with adress i must make it like this :&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;x00110101
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Where x is R/W bit ?
In Twi_sensor example we have&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#define MMA7660_ADDR        (0x98U &amp;gt;&amp;gt; 1)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What is compatible with my idea.&lt;/p&gt;
&lt;p&gt;3rd : I checked lines using a oscilloscope, they looks good. I tried example from this topic :
&lt;a href="https://devzone.nordicsemi.com/question/62372/i2c-how-do-i-specify-a-register-address-to-read-from-when-calling-nrf_drv_twi_rx/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Is this solution correct ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI starting</title><link>https://devzone.nordicsemi.com/thread/47749?ContentTypeID=1</link><pubDate>Wed, 16 Mar 2016 09:30:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57ea87b9-f887-4c62-a4cb-4c5e56759ff8</guid><dc:creator>MartinBL</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The left shifting of the address is always a source of confusion (and of good reasons). The thing is that the TWI operates with 7-bit addresses, but whenever you perform a TX or RX the address is left shifted once. This is usually done for you by hardware (or the driver). Then the Least Significant Bit (LSB) is set to either &amp;#39;0&amp;#39; or &amp;#39;1&amp;#39; to indicate whether you want to do a RX or a TX operation respectively.&lt;/p&gt;
&lt;p&gt;So in binary, address 0x49 equals: 1001001b&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;During a RX operation the address + LSB exposed on the TWI lines will be 10010010b&lt;/li&gt;
&lt;li&gt;During a TX operation the address + LSB exposed on the TWI lines will be 10010011b&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since the LSB of 0x49 is a &amp;#39;1&amp;#39; I think it is safe to assume that the address you use is a 7-bit address.&lt;/p&gt;
&lt;p&gt;Now to the confusing part; The datasheets of TWI devices haven&amp;#39;t really decided on how to define the device address. Some manufacturers define the address as a 7-bit value meant to be left shifted before setting LSB to &amp;#39;0&amp;#39; or &amp;#39;1&amp;#39;. Others define the address as an 8-bit value where you are &lt;em&gt;not&lt;/em&gt; meant to do any left shifting, but only set the LSB to &amp;#39;0&amp;#39; or &amp;#39;1&amp;#39;. In addition to this, TWI drivers might not always clarify whether it wants a 7 or 8-bit address, with or without the read/write bit already set.&lt;/p&gt;
&lt;p&gt;I looks like  you use SDK 11(?) though, so the transfer functions want a 7-bit address, e.g. 0x49.&lt;/p&gt;
&lt;p&gt;From the brief of &lt;code&gt;nrf_drv_twi_tx()&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; * @param[in] address    Address of a specific slave device **(only 7 LSB).**
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Other than that your code looks fine, but it seems like you have initiated your TWI driver in blocking mode, as you have not passed a TWI event handler to &lt;code&gt;nrf_drv_twi_init()&lt;/code&gt;. This means that your code will stay in &lt;code&gt;nrf_drv_twi_xx()&lt;/code&gt; forever if something goes wrong (e.g. if you use the wrong address).&lt;/p&gt;
&lt;p&gt;Finally I would suggest that you try to debug your code like &lt;a href="https://devzone.nordicsemi.com/question/60125/my-device-is-freezing-and-restarting/?answer=60126#post-id-60126"&gt;this&lt;/a&gt;. It might give you a clue of what the TWI driver is up to.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>