<?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>nRF52840 - SDK16 - Understanding TWI driver</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/65273/nrf52840---sdk16---understanding-twi-driver</link><description>Hi everyone, 
 I am looking the TWI examples and I am confused regarding the nrf_drv_twi_tx and nrf_drv_twi_rx . What I&amp;#39;ve understand so far is that the nrf_drv_twi_tx function is used either to write on a register or before reading a register right </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 01 Sep 2020 06:03:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/65273/nrf52840---sdk16---understanding-twi-driver" /><item><title>RE: nRF52840 - SDK16 - Understanding TWI driver</title><link>https://devzone.nordicsemi.com/thread/267336?ContentTypeID=1</link><pubDate>Tue, 01 Sep 2020 06:03:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4932e7e-6ec3-4b1c-913a-cc7625527323</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you for your assistance Jared&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - Understanding TWI driver</title><link>https://devzone.nordicsemi.com/thread/267222?ContentTypeID=1</link><pubDate>Mon, 31 Aug 2020 11:54:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ccdd3295-1bcb-413b-9971-feb463b5056a</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;[quote user="Nikosant03"][/quote]&lt;/p&gt;
&lt;p&gt;So the &lt;em&gt;len&amp;nbsp;&lt;/em&gt;parameter is the length of the buffer right?&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;blockquote&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;The&amp;nbsp;&lt;em&gt;len&amp;nbsp;&lt;/em&gt;parameter of the&amp;nbsp;nrf_drv_twi_tx() function is the number of bytes are being sent so yes it&amp;#39;s effectively the length of the transmit buffer.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Nikosant03"]But in order to write the whole the len parameter must be equal to the array size right? For example looking the funtion definition below. If the size of the p_data is 4byte and length = 3, then it will transmit the first three byte of the buffer, right?[/quote]
&lt;p&gt;&amp;nbsp;Yes? I&amp;#39;m not sure where this would contradict with my previous comment? &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - Understanding TWI driver</title><link>https://devzone.nordicsemi.com/thread/266985?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 11:38:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8dcbf5fc-4f8f-4b1f-a550-3977ec227003</guid><dc:creator>Nikosant03</dc:creator><description>&lt;p&gt;Thank you for your great responce Jared!!&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/65273/nrf52840---sdk16---understanding-twi-driver/266919"]The length of the register is usually 1 byte.[/quote]
&lt;p&gt;So the &lt;em&gt;len&amp;nbsp;&lt;/em&gt;parameter is the length of the buffer right?&lt;/p&gt;
[quote userid="73165" url="~/f/nordic-q-a/65273/nrf52840---sdk16---understanding-twi-driver/266919"]So what happens is that the I2C master will start with the first byte which contains the register address that it wants to write to and then follow up with 1 byte at a time until it has written the whole array.&amp;nbsp;[/quote]
&lt;p&gt;But in order to write the whole the len parameter must be equal to the array size right? For example looking the funtion definition below. If the size of the p_data is 4byte and length = 3, then it will transmit the first three byte of the buffer, right?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * @brief Function for sending data to a TWI slave.
 *
 * The transmission will be stopped when an error occurs. If a transfer is ongoing,
 * the function returns the error code @ref NRF_ERROR_BUSY.
 *
 * @param[in] p_instance Pointer to the driver instance structure.
 * @param[in] address    Address of a specific slave device (only 7 LSB).
 * @param[in] p_data     Pointer to a transmit buffer.
 * @param[in] length     Number of bytes to send.
 * @param[in] no_stop    If set, the stop condition is not generated on the bus
 *                       after the transfer has completed successfully (allowing
 *                       for a repeated start in the next transfer).
 *
 * @retval NRF_SUCCESS                  If the procedure was successful.
 * @retval NRF_ERROR_BUSY               If the driver is not ready for a new transfer.
 * @retval NRF_ERROR_INTERNAL           If an error was detected by hardware.
 * @retval NRF_ERROR_INVALID_ADDR       If the EasyDMA is used and memory adress in not in RAM.
 * @retval NRF_ERROR_DRV_TWI_ERR_ANACK  If NACK received after sending the address in polling mode.
 * @retval NRF_ERROR_DRV_TWI_ERR_DNACK  If NACK received after sending a data byte in polling mode.
 */
__STATIC_INLINE
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * p_instance,
                          uint8_t               address,
                          uint8_t const *       p_data,
                          uint8_t               length,
                          bool                  no_stop);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52840 - SDK16 - Understanding TWI driver</title><link>https://devzone.nordicsemi.com/thread/266919?ContentTypeID=1</link><pubDate>Fri, 28 Aug 2020 09:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0732d177-cf42-4945-aa8c-3d3dc1cff109</guid><dc:creator>Jared</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;To answer your questions:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Before the I2C master can read from a slave it would have to send the specific register that it wants the slave to output the data from i.e the register that it wants to read. This is the reason a transmission (tx) is done before a read (rx). The length of the register is usually 1 byte.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;The reason that the address is put at the start of the array is because it allows the driver to a continues write of the whole array without restarting the process. So what happens is that the I2C master will start with the first byte which contains the register address that it wants to write to and then follow up with 1 byte at a time until it has written the whole array.&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;I think &lt;a href="https://www.robot-electronics.co.uk/i2c-tutorial"&gt;this site&lt;/a&gt; is good resource for understanding the I2C protocol.&lt;/p&gt;
&lt;p&gt;Hope it helps :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;regards&lt;/p&gt;
&lt;p&gt;Jared&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>