<?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 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83733/nrf52840-i2c-address</link><description>Hello Everyone, 
 
 I am working on NRF52840 development kit. I am trying to run I2c master. My main goal is to send some data to slave via I2C lines. I am using the example code &amp;quot;TWI scanner&amp;quot; from the sdk examples. I have attached the slave microcontroller</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 14 Feb 2022 16:47:16 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83733/nrf52840-i2c-address" /><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352965?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 16:47:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3de32cf7-86b9-47a0-af60-57b64c03c15a</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Please get a logic analyzer so you can observe the data.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352887?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 13:03:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f1216865-e3f8-427e-8fec-02403793654d</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; I tried doing that also but no luck. The strange part is when I try to initialize it using the function below, I get a SUCCESS message, but when I try to send data to samd20 nothing is being received on samd20.&lt;/p&gt;
&lt;p&gt;SAMD20_ADDR = 0X54;&lt;/p&gt;
&lt;p&gt;bool samd20_i2c_init(void)&lt;br /&gt;{&lt;br /&gt; ret_code_t err_code;&lt;br /&gt; // uint8_t address = 0x54; &lt;br /&gt; uint8_t sample_data = 0x00;&lt;/p&gt;
&lt;p&gt;err_code = nrf_drv_twi_rx(&amp;amp;m_twi,SAMD20_ADDR,&amp;amp;sample_data,sizeof(sample_data));&lt;br /&gt; if(err_code == NRF_SUCCESS)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;SUCCESS 999&amp;quot;);&lt;br /&gt; //flag_led = 1;&lt;br /&gt; return true;&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;FAILED&amp;quot;);&lt;br /&gt; return false;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t understand why I am not receiving anything on SAMD20.I am really stuck here badly and not understanding how to proceed.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards,&lt;/p&gt;
&lt;p&gt;Snehal.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352878?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 12:52:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf3d3cb3-ae81-4807-801a-cf0daa80969b</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Looking at the api for&amp;nbsp;nrf_drv_twi_tx() there is nothing preventing you from just set the first byte of p_data to your value instead of register_adress.&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;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352840?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 10:33:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:459e355f-9bef-4d9c-af3d-aef29eb4fddd</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; I am not having logic analyzer. I am not confusing between 2 addresses. I understand that slave address is used as an identifier by the master and register address is internal addresses of the slave device. But in my case, I dont have any registers in my slave device. So how to send data?? What to put in place of register address?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Regards,&lt;/p&gt;
&lt;p&gt;Snehal.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352838?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 10:30:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:42b2120a-57d6-4ef6-87fb-f3eede35e262</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I believe you are mixing a bit the Device (slave) address with the Register address(es). There are two typical sequences in 2-wire (I2C) transactions, to illustrate the write and read operations you can look at the below Figures:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644834518202v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1644834541239v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;I suggest that you add a logic analyzer to the 2-wire (I2C) pins to see the actual data.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/352822?ContentTypeID=1</link><pubDate>Mon, 14 Feb 2022 09:22:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1c6c5375-9531-49ca-a691-900dabe12381</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;Hi Kenneth,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I had one question. I have a I2c slave device SAMD20, I am able to initiate a connection with samd20. Now I want to send sample data &amp;quot;0xaa&amp;quot; through I2c. SAMD20 has no registers. It is directly configured as a slave device with slave id 0x54. How can i send data through i2c??&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am trying to use this code:-&amp;nbsp;&lt;/p&gt;
&lt;p&gt;bool samd20_register_write(uint8_t register_address, uint8_t value)&lt;br /&gt;{&lt;br /&gt; ret_code_t err_code;&lt;br /&gt; uint8_t tx_buf[SAMD20_ADDRESS_LEN+1];&lt;br /&gt; &lt;br /&gt; //Write the register address and data into transmit buffer&lt;br /&gt; tx_buf[0] = register_address;&lt;br /&gt; tx_buf[1] = value;&lt;/p&gt;
&lt;p&gt;//Set the flag to false to show the transmission is not yet completed&lt;br /&gt; m_xfer_done = false;&lt;br /&gt; &lt;br /&gt; //Transmit the data over TWI Bus&lt;br /&gt; err_code = nrf_drv_twi_tx(&amp;amp;m_twi, SAMD20_ADDRESS, tx_buf, SAMD20_ADDRESS_LEN+1, false);&lt;br /&gt; &lt;br /&gt; //Wait until the transmission of the data is finished&lt;br /&gt; while (m_xfer_done == false)&lt;br /&gt; {&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;// if there is no error then return true else return false&lt;br /&gt; if (NRF_SUCCESS != err_code)&lt;br /&gt; {&lt;br /&gt; return false;&lt;br /&gt; }&lt;br /&gt; &lt;br /&gt; return true; &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But I am confused what should I pass as register address?? I have only slave address configured in the slave which is 0x54.&amp;nbsp;&lt;span&gt;SAMD20_ADDRESS =0x54. How do I send data ??&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;samd20_register_write(register_address, 0xaa);&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Please help me on this.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/349145?ContentTypeID=1</link><pubDate>Mon, 24 Jan 2022 08:28:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11310fe3-dc83-401e-82ce-594ce2498c51</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Good to hear you have solved it. There should be nothing in specific needed to handle 3 slaves, you only need to update the address for each slave, and also I suggest wait for the previous transaction to complete before starting the next.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/349122?ContentTypeID=1</link><pubDate>Mon, 24 Jan 2022 07:21:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b840afaa-6961-4952-989b-f9bc91e264fd</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi Kenneth,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Thanks for your reply. I solved that issue. Now my question is I have 3 slaves connected to NRF52840 on the same I2C lines&amp;nbsp;&lt;span&gt;SCL pin as P1.09 and SDA pin as P0.11. I am able to connect to slave 1. Now for adding slave 2 and slave 3 do I need to add something extra or I can read all 3 slaves from the same instance??&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Warm Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Snehal.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/348276?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 12:26:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39bf1dbd-e70a-427b-bd9e-0e93722324e6</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;You can use the following macro from nrf_gpio.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/** @brief Macro for mapping port and pin numbers to values understandable for nrf_gpio functions. */
#define NRF_GPIO_PIN_MAP(port, pin) (((port) &amp;lt;&amp;lt; 5) | ((pin) &amp;amp; 0x1F))&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;e.g. scl =&amp;nbsp;NRF_GPIO_PIN_MAP(1,9);&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/348258?ContentTypeID=1</link><pubDate>Tue, 18 Jan 2022 11:25:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c747da14-0db6-4407-96b6-88a22a319f54</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;Thanks, I got it. I had one question. I tested my code with SDA and SCL lines as p026 and p027. Now if I want to use SCL pin as P1.09 and SDA pin as P0.11 how do I configure port 1 and port 0 seperately?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/348142?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 21:08:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e606a4f1-d016-4546-9d4d-dfbfd5c70032</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;I think I read somewhere that the&amp;nbsp;&lt;span&gt;ATSAMD20 can support multiple (e.g. 2) i2c slave addresses?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kenneth&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/348027?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 12:24:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1b312dac-73d8-4795-b842-0f8c49363171</guid><dc:creator>sne_333</dc:creator><description>&lt;p&gt;Thanks for your reply Kenneth. Something weird is happening at my side. I agree with your left bit shifting. I tried to test the code again. Now NRF52840 is scanning 2 addresses.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;my code is as follows:-&lt;/p&gt;
&lt;p&gt;int main(void){&lt;/p&gt;
&lt;p&gt;ret_code_t err_code;&lt;br /&gt; uint8_t address = (0x54U);&amp;nbsp;&lt;br /&gt; uint8_t data;&lt;br /&gt; bool detected_device = false;&lt;br /&gt; bool result = false;&lt;/p&gt;
&lt;p&gt;APP_ERROR_CHECK(NRF_LOG_INIT(NULL));&lt;br /&gt; NRF_LOG_DEFAULT_BACKENDS_INIT();&lt;/p&gt;
&lt;p&gt;NRF_LOG_INFO(&amp;quot;TWI scanner started.&amp;quot;);&lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt; twi_init();&lt;br /&gt; nrf_delay_ms(1000); // give some delay&lt;/p&gt;
&lt;p&gt;for (address = 1; address &amp;lt;= TWI_ADDRESSES; address++)&lt;br /&gt; {&lt;br /&gt; err_code = nrf_drv_twi_rx(&amp;amp;m_twi, address, &amp;amp;data, sizeof(data));&lt;br /&gt; if (err_code == NRF_SUCCESS)&lt;br /&gt; {&lt;br /&gt; detected_device = true;&lt;br /&gt; NRF_LOG_INFO(&amp;quot;TWI device detected at address 0x%x...0x%x&amp;quot;, address,data);&lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt; send_data();&lt;br /&gt; }&lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;void send_data(void)&lt;br /&gt;{&lt;br /&gt; ret_code_t err_code;&lt;br /&gt; uint8_t address = (0x54U);&lt;br /&gt; uint8_t sample_data=0xaa;&lt;br /&gt; uint8_t sample_data1;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; err_code = nrf_drv_twi_tx(&amp;amp;m_twi, address, &amp;amp;sample_data, sizeof(sample_data), true);&lt;br /&gt; //Wait for the transmission to get completed&lt;br /&gt; //while (m_xfer_done == false){}&lt;br /&gt; nrf_delay_ms(1000); // give some delay&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; // If transmission was not successful, exit the function with false as return value&lt;br /&gt; if (NRF_SUCCESS != err_code)&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;FAILED 1.&amp;quot;);&lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt; }&lt;br /&gt; else&lt;br /&gt; {&lt;br /&gt; NRF_LOG_INFO(&amp;quot;SUCCESS 1.&amp;quot;);&lt;br /&gt; NRF_LOG_FLUSH();&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is my log on nrf module :-&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;lt;info&amp;gt; app: TWI scanner started.&lt;br /&gt;&amp;lt;info&amp;gt; app: TWI device detected at address 0x28...0x0&lt;br /&gt;&amp;lt;info&amp;gt; app: SUCCESS 1.&lt;br /&gt;&amp;lt;info&amp;gt; app: TWI device detected at address 0x54...0xAA&lt;br /&gt;&amp;lt;info&amp;gt; app: SUCCESS 1.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;0XAA is the data which I had sent to the slave. Now why is it scanning 2 addresses when I have attached only one slave with address 0x54??&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF52840 I2C ADDRESS.</title><link>https://devzone.nordicsemi.com/thread/348003?ContentTypeID=1</link><pubDate>Mon, 17 Jan 2022 11:41:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:49fa5561-816d-4ded-9f2a-3720da7f0b35</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Typically i2c is 7-bit address followed by an 8th-bit that indicate read or write. Making up a total of 8-bit i2c transaction. When there is mismatch between i2c address set and the actual i2c address that the scanner finds, then it typically due to a bit shifting that occured when creating the 7-bit address on the slave (typically done by shifting the address one bit to the left,&amp;nbsp;there one bit can be masked out). It is likely this is the case here, but you may need to try several adresses or use a logic analyzer to more easily understand this.&lt;/p&gt;
&lt;p&gt;0x54: 01010100 (shifting 1bit to the left and masking out the MSB: 0101000).&lt;br /&gt;0x28: 00101000&lt;/p&gt;
&lt;p&gt;At least that is what I expect.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>