<?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 Read and Write</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90982/nrf52832-twi-read-and-write</link><description>Hi there, 
 I&amp;#39;m developing with the nRF52832 right now. 
 I want to communicate nrf52832 (as master) with MP2723 to read and write data with TWI.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 19 Aug 2022 11:07:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90982/nrf52832-twi-read-and-write" /><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/382437?ContentTypeID=1</link><pubDate>Fri, 19 Aug 2022 11:07:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a84bcbc-eefd-45f6-ad83-9edea978f32b</guid><dc:creator>Einarh</dc:creator><description>[quote user="Sushi_27"]value is changed&amp;nbsp; after writing to it.[/quote]
&lt;p&gt;I don&amp;#39;t understand, is this not expected?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/382420?ContentTypeID=1</link><pubDate>Fri, 19 Aug 2022 10:00:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84bd8be1-b8c7-4988-af50-af39ccf08d6a</guid><dc:creator>Sushi_27</dc:creator><description>&lt;p&gt;Sorry for late response.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The problem is that slave register&amp;#39;s&amp;nbsp; value is changed&amp;nbsp; after writing to it. I don&amp;#39;t know that I should write it again or what should be done to get back to the default value.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;( slave register with address 0x00 had default value 0x48. But now its showing 0x00 )&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/382417?ContentTypeID=1</link><pubDate>Fri, 19 Aug 2022 09:54:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6593af55-0d00-403b-bf5c-81af65b6f263</guid><dc:creator>Sushi_27</dc:creator><description>&lt;p&gt;Thanks for the references.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m able to communicate with the slave.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381534?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 10:43:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2cf2a181-4486-46d5-ac68-040b33e1afbb</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;If you are unfamiliar with I2C or NCS and not sure how to get started, I would recommend having a look at the Nordic DevAcademy:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://academy.nordicsemi.com/lessons/lesson-6-serial-com-i2c/"&gt;https://academy.nordicsemi.com/lessons/lesson-6-serial-com-i2c/&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381532?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 10:35:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3284a7ee-a3c5-4526-b89d-8751539bf2b1</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Ok, that&amp;#39;s what you want to do, but what is your issue? What isn&amp;#39;t working as expected?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381527?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 10:02:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d1e6e5ca-5696-4ae8-beb2-38f600584e4d</guid><dc:creator>Sushi_27</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&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_error.h&amp;quot;
#include &amp;quot;pca10040.h&amp;quot;
#include &amp;quot;nrf_drv_twi.h&amp;quot;
#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

/* TWI instance ID. */

#define TWI_INSTANCE_ID     0 // create a ID constant


// create a handle which will point to TWI instance, in this case its TWI_0
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

// a function to initialize the twi(i2c)
void twi_init(void)
{
  ret_code_t err_code; // a variable to hold error code

// Create a struct with configurations and pass the values to these configurations.
  const nrf_drv_twi_config_t twi_config = {
    .scl                = ARDUINO_SCL_PIN, // P0.27
    .sda                = ARDUINO_SDA_PIN, // P0.26 
    .frequency          = NRF_DRV_TWI_FREQ_100K, // set the communication speed to 100K, we can select 250k or 400k as well
    .interrupt_priority = APP_IRQ_PRIORITY_HIGH, // Interrupt priority is set to high, keep in mind to change it if you are using a soft-device
    .clear_bus_init     = false // automatic bus clearing 

  };

  err_code = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL); // initialize the twi
  APP_ERROR_CHECK(err_code); // check if any error occured during initialization

  nrf_drv_twi_enable(&amp;amp;m_twi); // enable the twi comm so that its ready to communicate with the MP2723

}

/**
 * @brief Function for main application entry.
 */
int main(void)
{

  ret_code_t err_code; // a variable to hold error code value
  uint8_t address = 0x4b; // address of the MP2723
  uint8_t sample_data = 0x00; // sample data initialized with 0 value.

// initialize the Logger so that we can print msgs on the logger
  APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); 
  NRF_LOG_DEFAULT_BACKENDS_INIT();

  NRF_LOG_INFO(&amp;quot;Application Started&amp;quot;);

  NRF_LOG_FLUSH(); // flushing is necessary if deferred is set to 1(check this video tutorial to know it better)

  twi_init(); // call the twi initialization function

// read some data from the sensor
  err_code = nrf_drv_twi_rx(&amp;amp;m_twi, address, &amp;amp;sample_data, sizeof(sample_data));
  if(err_code == NRF_SUCCESS) // if reading data was successful
  {

    NRF_LOG_INFO(&amp;quot;Successfully detected a device at address: 0x%x&amp;quot;, address); // let the users know its working
  
    }

    NRF_LOG_FLUSH(); // flushing is important, if you set the deffered to 1, if deffered is set to 0 then we don&amp;#39;t need to flush the log buffer.
  


    while (true)
    {
        /* Empty loop. */
    }
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve attached the sample code.&lt;/p&gt;
&lt;p&gt;I want to implement -&lt;/p&gt;
&lt;p&gt;1) Read the Register of MP2723 and get register value (whatever it is) in terminal.&lt;/p&gt;
&lt;p&gt;2) Write - to make changes and get that value in terminal.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381519?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 09:31:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f2012a7-fb5a-4e23-9444-cdcc74e74770</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Then please explain the issues you are facing.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381506?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 09:11:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e9990ab7-a41f-45d9-9e44-55a827b063df</guid><dc:creator>Sushi_27</dc:creator><description>&lt;p&gt;okay.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve tried the twi&amp;nbsp; example of sdk but I&amp;#39;am&amp;nbsp; facing issue to read the register data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 TWI Read and Write</title><link>https://devzone.nordicsemi.com/thread/381491?ContentTypeID=1</link><pubDate>Mon, 15 Aug 2022 08:26:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05793de5-34a8-4cb0-b1cd-f27b1b824d70</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Here&amp;#39;s the functional description of the hardware:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwi.html"&gt;https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Ftwi.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can use either of these two drivers:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/peripherals/i2c.html"&gt;http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/peripherals/i2c.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/twi/driver.html"&gt;http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/twi/driver.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>