<?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>nRF52832 TWI implementation with 16-bit register addresses</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87300/nrf52832-twi-implementation-with-16-bit-register-addresses</link><description>We need to read/write to an I2C device that uses a 16-bit register addresses (Melexis MLX90632), and the nrf_drv_twi_tx() and nrf_drv_twi_rf() functions seem to be limited to 8-bit addresses. 
 How can we use the TWI module to read 16-bit addressed registers</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Apr 2022 13:48:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87300/nrf52832-twi-implementation-with-16-bit-register-addresses" /><item><title>RE: nRF52832 TWI implementation with 16-bit register addresses</title><link>https://devzone.nordicsemi.com/thread/364982?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 13:48:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c6ca1da-7b9f-46de-85ff-f9f02dfc5e07</guid><dc:creator>Jackson Wilson</dc:creator><description>&lt;p&gt;I had already reviewed all those links before I submitted my question.&amp;nbsp; They were not specific enough.&lt;/p&gt;
&lt;p&gt;I do mean &amp;quot;register address&amp;quot;, not &amp;quot;device address&amp;quot;.&lt;/p&gt;
&lt;p&gt;My question is very specifically about the&amp;nbsp;&lt;span&gt;nrf_drv_twi_tx() function.&amp;nbsp; An I2C read is a two-part process: (1) I2C write register address, (2) I2C read from that address.&amp;nbsp; So a&amp;nbsp;nrf_drv_twi_tx() is followed by&amp;nbsp;nrf_drv_twi_rx().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;The answer to my question is to break&amp;nbsp;the register address into an array of uint8_t type and write the bytes sequentially.&amp;nbsp; So a register address of 0x1234 can be written as 2 bytes:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint8_t reg[] = {0x12, 0x34};  //decompose 16-bit address, MSB first
err_code = nrf_drv_twi_tx(&amp;amp;m_twi, DVC_I2C_ADDR, reg, 2, false);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This simple answer hopefully will help others who ask the same question about 16-bit and 32-bit register addressing using the nrf_drv_twi_tx() question.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 TWI implementation with 16-bit register addresses</title><link>https://devzone.nordicsemi.com/thread/364811?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 06:14:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fe75096-da35-44dd-9618-98a0a17018e5</guid><dc:creator>JaTi</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/54277/twi-read-with-32-bits-register-address-return-all-zeros" rel="noopener noreferrer" target="_blank"&gt;Here&lt;/a&gt; a user describes accessing a device which uses a &lt;em&gt;32 bit address&lt;/em&gt;, maybe the proposed configuration is interesting for you.&lt;br /&gt; In &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/62384/how-does-nrf_drv_twi_tx-write-to-16-bit-register-address" rel="noopener noreferrer" target="_blank"&gt;this question&lt;/a&gt; another user has the same question as you do - the answer contains multiple links to additional ressources learning about I2C in general and notes:&lt;/p&gt;
[quote userid="6462" url="~/f/nordic-q-a/62384/how-does-nrf_drv_twi_tx-write-to-16-bit-register-address/254197#254197"]&lt;p&gt;Note that I2C itself has no notion of &amp;quot;registers&amp;quot; - that&amp;#39;s just to do with the particular Slave you&amp;#39;re talking to.&lt;/p&gt;
&lt;p&gt;As far as&amp;nbsp;&lt;span&gt;I2C itself is concerned, it&amp;#39;s all just &lt;em&gt;&lt;strong&gt;data&lt;/strong&gt;&lt;/em&gt;.&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;&lt;/p&gt;
[quote userid="79066" url="~/f/nordic-q-a/87300/nrf52832-twi-implementation-with-16-bit-register-addresses"]functions seem to be limited to 8-bit addresses[/quote]
&lt;p&gt;Do you mean the I2C device address? I think the I2C protocol specifies 7 bit standard addresses and 10 bit addressing to expand the number of devices connected to the same bus.&lt;br /&gt;&lt;br /&gt;I assume you confuse the I2C device address with the &amp;quot;register address&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The &lt;strong&gt;datasheet&lt;/strong&gt; of the &lt;em&gt;Melexis MLX90632 states (on &lt;strong&gt;p.22&lt;/strong&gt;):&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;em&gt; &amp;quot;&lt;span style="font-size:inherit;"&gt;&lt;span class="markedContent" id="page89R_mcid5"&gt;&lt;span style="font-family:sans-serif;left:72.8px;top:192.275px;" dir="ltr"&gt;By default, the device responds to the 7-bit slave address 0x3A.&lt;/span&gt;&lt;/span&gt;&lt;span class="markedContent" id="page89R_mcid6"&gt;&lt;br /&gt;&lt;span style="font-family:sans-serif;left:72.8px;top:214.675px;" dir="ltr"&gt;Configuration of the 7-bit slave address is possible at EEPROM address 0x24D5.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;Section 9.2 Addressed read&lt;/strong&gt; of the datasheet (&lt;strong&gt;p.24&lt;/strong&gt;) shows how to perform a read from a 16-bit address on the device.&lt;br /&gt;1. Send the 7-bit device address&lt;br /&gt;2. Send the MSB of the 16 bit address&lt;br /&gt;3. Send the LSB of the 16 bit address&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;JaTi&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>