<?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>Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74224/unable-to-write-8210-bytes-on-i2c-bus</link><description>Hi, 
 I am facing the issue of sending 8210 bytes of data to my slave device. 
 I am using NRF52840 interfaced with the MAX32664 maxim sensor hub. 
 I tried both approaches to transmit data with a legacy as well as easyDMA enabled case. 
 On the forum</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 26 Apr 2021 05:16:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74224/unable-to-write-8210-bytes-on-i2c-bus" /><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306672?ContentTypeID=1</link><pubDate>Mon, 26 Apr 2021 05:16:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63fc6020-aa42-40ad-9ad7-acb6421e7de5</guid><dc:creator>Gaurav Dubey</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;Thanks for your help, each and every suggestion given by you helped me narrow down my issues.&lt;/p&gt;
&lt;p&gt;I ultimately resolved the issue and able to write all the pages successfully.&lt;/p&gt;
&lt;p&gt;I wanted to tag your second last reply as a verified answer but it doesn&amp;#39;t show me options.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Regards&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Gaurav&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306499?ContentTypeID=1</link><pubDate>Fri, 23 Apr 2021 10:05:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e549b5f3-554f-4d22-99c6-0e78969d0be2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Error code 16 means&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.2.0/group__nrf__error.html#gabc562e4ddfe2f427666a3acdd0b469a3"&gt;NRF_ERROR_INVALID_ADDR&lt;/a&gt;. If you are declaring 28 static buffers containing 8210 bytes, this will consume 224kB of RAM, which is almost the full RAM size of the nRF52840 (256kB).&lt;/p&gt;
&lt;p&gt;From the API documentation for nrfx_twim_tx, you can see the reason for this error code:&lt;/p&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td colspan="1" rowspan="1"&gt;NRFX_ERROR_INVALID_ADDR&lt;/td&gt;
&lt;td colspan="1" rowspan="1"&gt;The provided buffer is not placed in the Data RAM region.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Most likely, the buffers does not fit in RAM and cause some issues. Do you need to declare all buffers at once, or can you re-use the same buffer for more than one transfer? Storing the data in flash initially and copy it to one or a couple buffers while transmitting may be a better approach.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306418?ContentTypeID=1</link><pubDate>Thu, 22 Apr 2021 16:41:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc068df7-eb5b-4e74-8341-c9f6aaac4551</guid><dc:creator>Gaurav Dubey</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;I migrated from code nrfx_twi to nrfx_twim successfully.&lt;/p&gt;
&lt;p&gt;I want to write 28 pages&amp;nbsp; (28 x 8210bytes) 1 page at a time.&lt;/p&gt;
&lt;p&gt;for the same, I have made 28 static buffers in the code containing 8210 bytes in a sequence.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now with your suggestions, I have written 13 pages successfully out of 28 but as soon as&amp;nbsp;&lt;span style="font-family:inherit;"&gt;it tries to write the 14th page the function returns&lt;strong&gt; error code 16&lt;/strong&gt;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;what error code 16 refers to?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;how do I resolve it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1619109241117v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Thank you&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-Gaurav&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306294?ContentTypeID=1</link><pubDate>Thu, 22 Apr 2021 10:53:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71f4a20b-fc4a-4d08-8f79-bb1d4d313572</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;I believe you get this error because the function uses too long time to transfer the data when you are using the nrfx_twi driver in blocking mode, leading to a &lt;a href="https://github.com/NordicSemiconductor/nrfx/blob/v1.8.6/drivers/src/nrfx_twi.c#L460-L464"&gt;HW timeout&lt;/a&gt; in the driver.&lt;/p&gt;
&lt;p&gt;I would highly recommend you to switch to using the nrfx_twim driver, as this handles the long transfers in HW, by fetching the data directly from RAM. In nrfx_twi, only one byte is provided to the peripheral by the CPU at a time, leading to much interrupt/event overhead and CPU usage. It would also be beneficial if you add an event handler in your application, to run in &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/hardware_driver_twi.html#hardware_driver_twi_basic"&gt;non-blocking mode&lt;/a&gt;. This would eliminate the HW timeout used in blocking mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306182?ContentTypeID=1</link><pubDate>Wed, 21 Apr 2021 16:25:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd22a3ab-db2d-4378-a2b7-9743db4e5537</guid><dc:creator>Gaurav Dubey</dc:creator><description>&lt;p&gt;Information: all other reads/writes commands are working this happens just when the buffer size is 8210 bytes&lt;/p&gt;
&lt;p&gt;nrfx_twi_tx function call gives error code 3 only when I write 1st page of 8210 bytes for all other small transaction it is working.&lt;/p&gt;
&lt;p&gt;Initialization in main:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//initialization:
ret_code_t err_code;
const nrfx_twi_config_t twi_max32664_config = {
.scl = ARDUINO_SCL_PIN,
.sda = ARDUINO_SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.hold_bus_uninit = false
};

err_code = nrfx_twi_init(&amp;amp;m_twi, &amp;amp;twi_max32664_config, NULL, NULL);
APP_ERROR_CHECK(err_code);
nrfx_twi_enable(&amp;amp;m_twi);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;write cmd function :&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    //write command function definition
    SS_STATUS write_cmd(uint8_t *tx_buf, int tx_len, int sleep_ms) {

	me11_i2c_wakeup_call();
	ret_code_t err_code = me11_write(tx_buf, tx_len, false);

	int retries = 4;
	while (err_code != NRF_SUCCESS &amp;amp;&amp;amp; retries-- &amp;gt; 0) {
		NRF_LOG_INFO(&amp;quot;i2c wr retry = %d&amp;quot; , err_code);
		NRF_LOG_FLUSH();
		i_mxc_delay(1000);
		me11_i2c_wakeup_call();
		err_code = me11_write(tx_buf, tx_len, false);
	}

	if (err_code != 0) {
		NRF_LOG_INFO(&amp;quot;write_cmd error SS_ERR_UNAVAILABLE = %d&amp;quot; , err_code);
		NRF_LOG_FLUSH();
		return SS_ERR_UNAVAILABLE;
	}

	nrf_delay_ms(sleep_ms);
	uint8_t status_byte;

	me11_i2c_wakeup_call();
	err_code = me11_read( &amp;amp;status_byte, 1, false);

#if 1	//optional
	bool try_again = (status_byte == SS_ERR_TRY_AGAIN);
	while ((err_code != NRF_SUCCESS || try_again) &amp;amp;&amp;amp; retries-- &amp;gt; 0) {
		i_mxc_delay(sleep_ms * 1000);
		me11_i2c_wakeup_call();
		err_code = me11_read( &amp;amp;status_byte, 1, false);
		try_again = (status_byte == SS_ERR_TRY_AGAIN);
	}
#endif

	return (SS_STATUS)status_byte;

}

void me11_i2c_wakeup_call(void){

#if 1
	uint8_t tx_buf[1];
	tx_buf[0] = 0x00;


	nrfx_twi_tx(&amp;amp;m_twi,0x00,&amp;amp;tx_buf[0],1,false); //GD

	i_mxc_delay(200); //GD might need calibration

	tx_buf[0] = 0xD3;
	tx_buf[0] = 0x00;

	nrfx_twi_tx(&amp;amp;m_twi,0x00,&amp;amp;tx_buf[0],1,false); //GD
	i_mxc_delay(150);




#else

	
	uint8_t tx_buf[1] = {0xFF};
	nrfx_twi_tx(&amp;amp;m_twi,I2C_SLAVE_ADDR,&amp;amp;tx_buf[0],1,FALSE);
	nrfx_twi_tx(&amp;amp;m_twi,I2C_SLAVE_ADDR,&amp;amp;tx_buf[0],1,FALSE);
	nrfx_twi_tx(&amp;amp;m_twi,I2C_SLAVE_ADDR,&amp;amp;tx_buf[0],1,FALSE);
	nrfx_twi_tx(&amp;amp;m_twi,I2C_SLAVE_ADDR,&amp;amp;tx_buf[0],1,FALSE);
	 */

#endif

}

int me11_write( const uint8_t *data, int length, bool repeated){
	ret_code_t err_code;
	
	err_code = nrfx_twi_tx(&amp;amp;m_twi,I2C_SLAVE_ADDR,(uint8_t *)data, length,repeated);
	if(err_code != NRF_SUCCESS)
	{
		NRF_LOG_INFO(&amp;quot;mel1_write err_code= %d&amp;quot;, err_code);
//		APP_ERROR_CHECK(err_code);
	}

	return err_code;
}

int me11_read( uint8_t *data, int length, bool repeated){
	ret_code_t err_code;
	
	err_code = nrfx_twi_rx(&amp;amp;m_twi,I2C_SLAVE_ADDR,(uint8_t *)data, length);
	if(err_code != NRF_SUCCESS)
	{
		NRF_LOG_INFO(&amp;quot;mel1_read err_code= %d&amp;quot;, err_code);
//		APP_ERROR_CHECK(err_code);
	}
	return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;calling write_cmd:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Function call:

status = write_cmd(cmd_bytes_4c_to_205b, sizeof(cmd_bytes_4c_to_205b),340);&amp;#160;

//size of cmd_bytes_4c_to_205b = 8210 bytes

if(status!=SS_SUCCESS)
{
NRF_LOG_INFO(&amp;quot;FAILED to send page bytes 0x4C to 0x205B from the .msbl file SIZE:%d status byte:0x%x&amp;quot;,sizeof(cmd_bytes_4c_to_205b),status);
NRF_LOG_FLUSH();
}
else
{
NRF_LOG_INFO(&amp;quot;SUCCESFULL to send page bytes 0x4C to 0x205B from the .msbl file SIZE:%d&amp;quot;,sizeof(cmd_bytes_4c_to_205b));
NRF_LOG_FLUSH();
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/306067?ContentTypeID=1</link><pubDate>Wed, 21 Apr 2021 11:13:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74b5ad4d-43fc-4ca8-9e6d-be45d87916f2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Error code 3 means &lt;span&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.s140.api.v7.2.0/group__nrf__error.html#gadf8b0c33ea15352808e5ac7f69c2be8a"&gt;NRF_ERROR_INTERNAL&lt;/a&gt;. Which function is returning this error?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Can you post your code for initializing of TWI and how you do the transfers?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/305996?ContentTypeID=1</link><pubDate>Wed, 21 Apr 2021 07:38:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8430387c-3f0f-410e-9367-f039fda33cfe</guid><dc:creator>Gaurav Dubey</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;I have migrated the code from nrf_drv_twi&amp;nbsp; to nrfx_twi where API uses size_t&amp;nbsp; as the length parameter.&lt;/p&gt;
&lt;p&gt;Now when I am trying to write the bytes it sends 1380 bytes and sends error code 3.&lt;/p&gt;
&lt;p&gt;what does error code 3 means?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Unable to write 8210 bytes on I2c bus</title><link>https://devzone.nordicsemi.com/thread/305914?ContentTypeID=1</link><pubDate>Tue, 20 Apr 2021 14:36:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b1bc41e7-89e2-4868-8e49-2a349d1e2f3b</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you are using the nrf_drv_twi API, this uses a uint8_t parameter for the length parameters to the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrf__drv__twi.html#ga6c83eac2d358bc8fb5b53c53f22506b6"&gt;tx&lt;/a&gt;/&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrf__drv__twi.html#gab135f4b02e2f7dcd8db59f17063617ff"&gt;rx&lt;/a&gt; functions. This variable will overflow when you exceed 255 bytes transfer length. The reasoning behind this was that nRF52832 had a hardware limitation of 255 byte transfers (&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/twim.html#register.TXD.MAXCNT"&gt;8-bit length&lt;/a&gt;) in the TWIM peripheral. For nRF52840, this HW limitation is extended to 65535 bytes (&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/twim.html#register.TXD.MAXCNT"&gt;16-bit length&lt;/a&gt;). To use the support for longer transfers, you need to &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/nrfx_migration_user_guide.html?cp=7_1_2_7_1#getting_started_replace_nrf_drv_options_migrate"&gt;migrate to the new nrfx drivers&lt;/a&gt;, which use &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__twim.html?cp=7_1_6_8_0_39_0_29#gaca8c4ae7f10409b7ca2b838fa1ac41dd"&gt;size_t/uint32_t&lt;/a&gt; for the length parameters.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>