<?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 Errata 89 workaround</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86365/twi-errata-89-workaround</link><description>I am using LSM6DSOX IMU sensor INT detection with NRF52-DK and have extra 400&amp;#181;A (PPK2 used) on my setup. After a few days of nightmares I finally found that this is related to Errata 89. The documentation says that there is a workaround, but I can&amp;#39;t figure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 30 Mar 2022 07:33:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86365/twi-errata-89-workaround" /><item><title>RE: TWI Errata 89 workaround</title><link>https://devzone.nordicsemi.com/thread/360673?ContentTypeID=1</link><pubDate>Wed, 30 Mar 2022 07:33:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:56d8aae7-caf0-4025-8685-8f7c51cf0904</guid><dc:creator>YaroslavRakhnenko</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void MLC_int_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
	i2c_init(); //Because the system in low power

	nrf_drv_gpiote_out_toggle(MLC_INT_LED);
	
	uint8_t MLC[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
	lsm6dsox_mlc_out_get(&amp;amp;dev_ctx, MLC);
	
	/* When putting the system in low power and the peripheral is not needed, 
	lowest possible power consumption is achieved by stopping, and then disabling the peripheral. */
	nrf_drv_twi_disable( &amp;amp;m_twi );
	nrf_drv_twi_uninit( &amp;amp;m_twi );
	
	/* Nordic work around to prevent burning excess power due to chip errata
	   Use 0x40003FFC for TWI0 */
	*(volatile uint32_t *)0x40003FFC = 0;
	*(volatile uint32_t *)0x40003FFC;
	*(volatile uint32_t *)0x40003FFC = 1;
}

...

/**
 * @brief	Function for i2c bus init.
 *
 * @param	none
 *
 */
void i2c_init()
{
  ret_code_t err_code;

  const nrf_drv_twi_config_t twi_config = {.scl                 = TWI_SCL_PIN,
                                            .sda                = TWI_SDA_PIN,
                                            .frequency          = (nrf_drv_twi_frequency_t)NRF_TWI_FREQ_400K,
                                            .interrupt_priority = APP_IRQ_PRIORITY_LOW,
                                            .clear_bus_init     = true};
  err_code                               = nrf_drv_twi_init(&amp;amp;m_twi, &amp;amp;twi_config, NULL, NULL);
  APP_ERROR_CHECK(err_code);
																	
	nrf_drv_twi_enable(&amp;amp;m_twi);
}

...


/**
 * @brief Function for application main entry.
 */
int main(void)
{
    ...
	
	gpio_init();
	i2c_init();

	/*
	*	Initialize mems driver interface
	*/
	dev_ctx.write_reg = i2c_LSM6DSOX_write;
	dev_ctx.read_reg 	= i2c_LSM6DSOX_read;
    dev_ctx.handle = NULL;

	/* Check device ID */
	static uint8_t whoamI=0, rst=0;
    lsm6dsox_device_id_get(&amp;amp;dev_ctx, &amp;amp;whoamI);
  		    		  	
	if (whoamI == LSM6DSOX_ID) 
	{
		 //Restore default configuration
		int ttl = 8;
		lsm6dsox_reset_set(&amp;amp;dev_ctx, PROPERTY_ENABLE);
		do {
			lsm6dsox_reset_get(&amp;amp;dev_ctx, &amp;amp;rst);
			if ((ttl-- &amp;lt; 0) &amp;amp;&amp;amp; rst) {
				return 1;
			}
		} while (rst);
  		  		
		...
		
		/* Nordic work around to prevent burning excess power due to chip errata
			 Use 0x40003FFC for TWI0 */
		*(volatile uint32_t *)0x40003FFC = 0;
		*(volatile uint32_t *)0x40003FFC;
		*(volatile uint32_t *)0x40003FFC = 1;
	}
	else
	{
		return 1;
	}
	
	for (;;)
	{
		idle_state_handle();
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks! Finally done!&lt;/p&gt;
&lt;p&gt;I will post the final code here (parts that I changed regarding my post), maybe it will come in handy for someone!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI Errata 89 workaround</title><link>https://devzone.nordicsemi.com/thread/360516?ContentTypeID=1</link><pubDate>Tue, 29 Mar 2022 11:40:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5ce14b7-2843-419a-a71e-14ea697b2850</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;You can find that there is a Low Power chapter when using the TWI in the product specification:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/twim.html#concept_twi_low_power"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/twim.html#concept_twi_low_power&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So after executing a twi transfer, you should always disable the twi until next transaction. Before each twi transfer you can enable the twi and start twi transfer. The only difference&amp;nbsp;due&amp;nbsp;to the Errata 89, is that you need to execute the lines specified in Errata 89 after disabling the twi transfer.&lt;/p&gt;
&lt;p&gt;I assume in your case you will need to add twi init and twi start transfer in&amp;nbsp;LSM6DSOX_int_pin_handler(). And in the twi callback handler you need to disable and call Errata 89 if no additional twi is needed until next&amp;nbsp;&lt;span&gt;LSM6DSOX_int_pin_handler().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>