<?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 transaction failed</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/67577/twi-transaction-failed</link><description>Hi, i am using: 
 -nRF 52 DK 
 -nRF 52832 
 -Sensor of Maxim Integrated 
 -SDK 17.0.2 
 I have some problems in handling the I2C through the nrfx module. 
 My I2C communication with the sensor is defined as a TX/RX. 
 I am using slightly different Read</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 Nov 2020 14:33:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/67577/twi-transaction-failed" /><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/279051?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 14:33:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4cfdcf4-5c64-48ff-8fc2-834b5db02992</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Polimarte!&lt;br /&gt;&lt;br /&gt;Sorry for my late reply - I have been out of office for some days.&lt;/p&gt;
[quote user="polimarte "]i finally i make it work![/quote]
&lt;p&gt;Great, that is fantastic news! I am glad to hear that you figured it out and were able to resolve your issues!&lt;br /&gt;I hope my comments and suggestions have been helpful to you in this endeavor.&lt;/p&gt;
[quote user="polimarte "]Thanks karl for the support!&amp;nbsp;[/quote]
&lt;p&gt;No problem at all, Polimarte, I am happy to help! :)&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/279035?ContentTypeID=1</link><pubDate>Mon, 09 Nov 2020 14:05:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5228368c-4718-4032-b7b9-5d5cd2549041</guid><dc:creator>polimarte </dc:creator><description>&lt;p&gt;Hi, i finally i make it work! i had some problems with SDA/SCL pins, now the first read is done correctly.&lt;/p&gt;
&lt;p&gt;Thanks karl for the support!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;polimarte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/278504?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 16:47:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:af6e06a3-9adb-49d0-8bf9-03390e42ebc0</guid><dc:creator>polimarte </dc:creator><description>&lt;p&gt;Hi Karl i really appreciate your help!&amp;nbsp;&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]This means that it will be called twice with the error_code returned by twim_xfer.[/quote]
&lt;p&gt;Thanks for the note i will call the APP_ERROR_CHECK only ones in this case. II had inserted the second one as a break in case of timeout only, but you are right is not useful implemented like that.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]It seems you are only getting this NACK on the READ command, following the first Write, is this correct?[/quote]
&lt;p&gt;No, unfortunately i have problem since the first read.&amp;nbsp;To work with my&amp;nbsp;sensor hub i have to enter in Application Mode first, through a sequence of set/clear of two pins, the Reset and the Mfio pin. This is working, even if i could not check with a logic analyzer i have seen the behave of the pins with the help of two leds. &lt;span&gt;I know it is very naive.&amp;nbsp;&lt;/span&gt;As well the sda and scl are set high, but nothing happen than. After this sequence i have the first read to apply in order to check the device mode.&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]If so, what is your OXI_ADDRESS_R - where did you find it, and what does the documentation say about this address?[/quote][quote userid="92644" url="~/f/nordic-q-a/67577/twi-transaction-failed/277191#277191"] &amp;quot;The MAX32664 uses 0xAA as the I2C 8-bit slave write address and 0xAB is used as the I2C 8-bit slave read address&amp;quot;[/quote]
&lt;p&gt;Initially i wrongly used two different slave adresses for the TX and RX transactions (OXI_ADDRESS_W=0xAA and OXI_ADRESS_R=0xAB) only than i noticed that the the nrfx_twim_*x nedeed the 7-bit address (LSB). So now i am using as address field 0x55 for both the transactions.&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]You will indeed need the twim_tx_done set, after a STOP condition is sent. As I understand it from your provided documentation screenshot, you need the CMD_DELAY to happen AFTER the stop condition is sent, and the twim_tx_done is set.[/quote]
&lt;p&gt;Thanks for this important specification about stop condition and non-blocking mode, i was a bit confused about that.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]As I understand it from your provided documentation screenshot, you need the CMD_DELAY to happen AFTER the stop condition is sent, and the twim_tx_done is set. [/quote]
&lt;p&gt;I had already tryed to insert some delay between the transactions in my previous modification of the code but still i had the NACK error. I will reintroduce this dalay between TX and the RX,&amp;nbsp;in the code that i have shared i have&amp;nbsp;&amp;nbsp;inserted a delay after the first xfer, i will change position of that.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]So, can you tell me, how long does the datasheet specify that the CMD_DELAY needs to be, and how long is your actual wait between the completion of the TX and the start of the RX, with your current code?[/quote]
&lt;p&gt;The datasheet states that &amp;quot;The master waits for a period of CMD_DELAY (2ms) for the device to have its data ready&amp;quot;. I have put a longer delay (6ms)&amp;nbsp;as it is in my version of the code for ARDUINO (that is working correctly). i don&amp;#39;t&amp;nbsp;think it is an issue.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I checked with the twi_scanner example the address. When i directly connect the sensor to the DK it finds the right address at 0x55. I tryed than to use my read/write byte functions and they complete the transactions (the twi_*x_done is set correctly). While connecting the sensor to nRF52832 i am able to check the correct address but i am still stack at our NACK error. I am using general digital pins 16 and 17 on the nrf52832 as SDA and SCL and i am sure to have defined correctly these pins in the twi_init function as well to have connected in the right way the DK to my nrf52832.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/278396#278396"]Looking forward to getting to the bottom of this![/quote]
&lt;p&gt;Thanks again Karl!&lt;/p&gt;
&lt;p&gt;polimarte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/278396?ContentTypeID=1</link><pubDate>Wed, 04 Nov 2020 09:56:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:83cb2c94-8124-47e9-919e-01387380eb78</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Polimarte,&lt;/p&gt;
[quote user="polimarte "]Yes you are right, i forgot the possibility of faulty interaction of the interrupts with timer variables.[/quote]
&lt;p&gt;I would not call it a faulty interaction, but yes, this is definitely something to consider. If accuracy is needed, a timer should be used instead.&lt;/p&gt;
[quote user="polimarte "]I have modified my code in order to retransmit at the arrival of the &lt;span&gt; &lt;/span&gt;twim_tx_failed (NACK event) or at the timeout of the timer.[/quote]
&lt;p&gt;&amp;nbsp;Great! Now it accounts for the possibility of a NACK atleast. I will note that APP_ERROR_CHECK() following your waiting while loop will be called regardless of the while loop ending due to a timeout or success. This means that it will be called twice with the error_code returned by twim_xfer. This might seem insignificant now, but it could induce some trouble if you later change your error handling.&lt;/p&gt;
[quote user="polimarte "]In this way till flag_retry is set the transaction starts again or abort in case of timeout with APP_ERROR_CHECK. I add also a delay after the transaction but still i am stack with NACK.[/quote]
&lt;p&gt;So, we will still need to resolve &lt;em&gt;why&lt;/em&gt; the NACK is sent. Why the slave device is not responding to the second call.&lt;br /&gt;Most likely ( if it is not a timing issue ), retransmission will not solve the issue in this case. You will for example get a NACK on the address if the address is not exposed on the device. Retrying the same address will then always generate NACK, since it will never be acknowledged.&lt;br /&gt;&lt;br /&gt;It seems you are only getting this NACK on the READ command, following the first Write, is this correct? If so, what is your OXI_ADDRESS_R - where did you find it, and what does the documentation say about this address?&lt;/p&gt;
[quote user="polimarte "]Maybe i am missing something but&amp;nbsp;i have set no flags on NRFX_TWIM_XFER_TX,&lt;span&gt;&amp;nbsp;&lt;/span&gt;allowing so the STOP condition. nrfx_twim_xfer without&amp;nbsp;NRFX_TWIM_FLAG_TX_NO_STOP is blocking, suitable with the waiting for the&amp;nbsp;twim_tx_done to be set, correct?&amp;nbsp;[/quote]
&lt;p&gt;No, this is incorrect. nrfx_twim_xfer is non blocking, even with the NO_STOP flag - this flag only means that no stop condition is generated between successive transfers. In your case, you will need a STOP condition when you switch between a read and a write command, and visa versa.&lt;/p&gt;
[quote user="polimarte "]I have read this, i have considered the CMD_DELAY between TX and RX solved by the possibility to have a check on the transaction state, having&amp;nbsp;twim_tx_done set and the STOP condition.[/quote]
&lt;p&gt;Sorry, I do not understand what you mean by this. You will indeed need the twim_tx_done set, after a STOP condition is sent. As I understand it from your provided documentation screenshot, you need the CMD_DELAY to happen AFTER the stop condition is sent, and the twim_tx_done is set. The CMD_DELAY is meant to give the slave time to prepare data / process the command, before the master may send a new command.&lt;br /&gt;So, can you tell me, how long does the datasheet specify that the CMD_DELAY needs to be, and how long is your actual wait between the completion of the TX and the start of the RX, with your current code?&lt;/p&gt;
[quote user="polimarte "]I tryied also to insert some delay after any twim_xfer, to give time to the transaction to be done.[/quote]
&lt;p&gt;I see that you have put a 6 ms delay here. What is the required CMD_DELAY as specified in the datasheet?&lt;br /&gt;&lt;br /&gt;Looking forward to getting to the bottom of this!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/278157?ContentTypeID=1</link><pubDate>Mon, 02 Nov 2020 18:42:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19e7b6a5-4704-42c6-9b4a-7940c2d91f4a</guid><dc:creator>polimarte </dc:creator><description>&lt;p&gt;Hi Karl!&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]While this implementation might function, you have no way to know how long this loop will take to complete - the time will vary for each call to your function. [/quote]
&lt;p&gt;Yes you are right, i forgot the possibility of faulty interaction of the interrupts with timer variables.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]Yes, and then have something else ( such as a retransmit ) happen if the NACK flag is set.[/quote]
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;I have modified my code in order to retransmit at the arrival of the &lt;span&gt; &lt;/span&gt;twim_tx_failed (NACK event) or at the timeout of the timer.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
{

    size_t primaryBufferSize = p_event-&amp;gt;xfer_desc.primary_length;
    uint8_t *bytesTransferred = p_event-&amp;gt;xfer_desc.p_primary_buf;
    size_t secondaryBufferSize = p_event-&amp;gt;xfer_desc.secondary_length;
    uint8_t *bytesRead = p_event-&amp;gt;xfer_desc.p_secondary_buf;

    switch (p_event-&amp;gt;type)
    {
        case NRFX_TWIM_EVT_DONE:
    
            NRF_LOG_INFO(&amp;quot;STATE OF BUFFERS IN EVENT HANDLER:&amp;quot;);
            NRF_LOG_INFO(&amp;quot;\t Size of primary buffer: %d&amp;quot;, primaryBufferSize);
            NRF_LOG_INFO(&amp;quot;\t Size of secondary buffer: %d&amp;quot;, secondaryBufferSize);
          
					if (p_event-&amp;gt;xfer_desc.type == NRFX_TWIM_XFER_TX)
            {
                twim_tx_done = true;
            }
          
					if (p_event-&amp;gt;xfer_desc.type == NRFX_TWIM_XFER_RX)
            {
                twim_rx_done = true;
            }
            break;
        
		case NRFX_TWIM_EVT_ADDRESS_NACK:
						if (p_event-&amp;gt;xfer_desc.type == NRFX_TWIM_XFER_TX)
            {
                twim_tx_failed = true;
            }
          
						if (p_event-&amp;gt;xfer_desc.type == NRFX_TWIM_XFER_RX)
            {
                 twim_rx_failed = true;
            }
            NRF_LOG_INFO(&amp;quot;Received NACK after sending address!&amp;quot;);
            break;
        
		case NRFX_TWIM_EVT_DATA_NACK:
            NRF_LOG_INFO(&amp;quot;Received NACK after sending data.&amp;quot;);
            break;
        default:
            break;
    }

	}
	
uint8_t readByte( uint8_t familyByte, uint8_t indexByte)
{
    
	
		uint8_t flag_retry=1;
	
		nrfx_err_t err_code;

		uint8_t StatusByte;    
        uint8_t ReturnByte;
   
        uint8_t rx_buffer[2];
		size_t rx_lenght =2;

		uint8_t tx_buffer[] = {familyByte, indexByte};    
		size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte);

		while(flag_retry==1){
		uint32_t timeout = OXI_TWI_TIMEOUT;
		nrfx_twim_xfer_desc_t tx_xfer = NRFX_TWIM_XFER_DESC_TX(OXI_ADDRESS_W, tx_buffer, tx_lenght);
		err_code = nrfx_twim_xfer(&amp;amp;twim_instance, &amp;amp;tx_xfer, 0);
		nrf_delay_ms(6);
		APP_ERROR_CHECK(err_code);
		
		while((!twim_tx_done) &amp;amp;&amp;amp; --timeout &amp;amp;&amp;amp; 	twim_tx_failed == false);
		if(!timeout) err_code=NRF_ERROR_TIMEOUT;
		APP_ERROR_CHECK(err_code);
		if(twim_tx_done) flag_retry=0;
		if(twim_tx_failed) flag_retry=1;
		}
		

		flag_retry=1;
		
		
		while(flag_retry==1){
		uint32_t timeout = OXI_TWI_TIMEOUT;
			
		nrfx_twim_xfer_desc_t rx_xfer = NRFX_TWIM_XFER_DESC_TX(OXI_ADDRESS_W, rx_buffer, rx_lenght);
		err_code = nrfx_twim_xfer(&amp;amp;twim_instance, &amp;amp;rx_xfer, 0);
		APP_ERROR_CHECK(err_code);
		
		while((!twim_rx_done) &amp;amp;&amp;amp; --timeout &amp;amp;&amp;amp; 	twim_rx_failed == false);
		if(!timeout) err_code=NRF_ERROR_TIMEOUT;
		APP_ERROR_CHECK(err_code);
		if(twim_rx_done) flag_retry=0;
		if(twim_tx_failed) flag_retry=1;
		}
		
		StatusByte = rx_buffer[0];
        NRF_LOG_INFO(&amp;quot;Status Byte: %lu \n&amp;quot;,StatusByte);
    
		ReturnByte = rx_buffer[1];  
		return ReturnByte;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;In this way till flag_retry is set the transaction starts again or abort in case of timeout with APP_ERROR_CHECK. I add also a delay after the transaction but still i am stack with NACK.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]This is correct, and with the current implementation this is as expected - since the nrfx_xfer function is non-blocking, it will return before the slave device has had the chance to NACK ( or otherwise misbehave ). [/quote]
&lt;p&gt;Maybe i am missing something but&amp;nbsp;i have set no flags on NRFX_TWIM_XFER_TX,&lt;span&gt;&amp;nbsp;&lt;/span&gt;allowing so the STOP condition. nrfx_twim_xfer without&amp;nbsp;NRFX_TWIM_FLAG_TX_NO_STOP is blocking, suitable with the waiting for the&amp;nbsp;twim_tx_done to be set, correct?&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"] Apart from the screenshot you should see a debug output if anything else than NRF_SUCCESS was returned.&amp;nbsp;[/quote]
&lt;p&gt;I have the RTT viewer which display the NACK and the TWIM viewer where the TX starts and the AMOUNT of bytes transferred is always 0. Where i can catch and show you other useful debug outputs?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]I did a quick search for the part number&amp;nbsp;&lt;a href="https://pdfserv.maximintegrated.com/en/an/user-guide-6806-max32664.pdf"&gt;MAX32664 and found this datasheet&lt;/a&gt;. Is this the part you are working with?[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Yes, i am working on it!&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]Among other things, it describes that the device needs a given CMD_DELAY to ready data for transfer - this could for example lead the device to NACK a request, since it is not yet ready to proceed with a transfer.&amp;nbsp;[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;I have read this, i have considered the CMD_DELAY between TX and RX solved by the possibility to have a check on the transaction state, having&amp;nbsp;twim_tx_done set and the STOP condition.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;/span&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277404#277404"]it describes that the device needs a given CMD_DELAY to ready data for transfer - this could for example lead the device to NACK a request, since it is not yet ready to proceed with a transfer.&amp;nbsp;[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;I tryied also to insert some delay after any twim_xfer, to give time to the transaction to be done.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&amp;nbsp;Thanks,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;polimarte&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/277404?ContentTypeID=1</link><pubDate>Wed, 28 Oct 2020 13:38:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ffe8df5-ff4a-45ed-8155-e8c39d983f05</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="polimarte "]I have modified my code with a timer in this way, introducing a timeout:&amp;nbsp;[/quote]
&lt;p&gt;While this implementation might function, you have no way to know how long this loop will take to complete - the time will vary for each call to your function. This is due to the fact that your readByte function might be interrupted during this loop - which would make the &amp;quot;timeout&amp;quot; rundown take longer.&lt;br /&gt;Additionally, since WFE is being used in the timeout loop, you will not necessarily know (unless you have a periodic event happening) how long this will take. Imagine a sequence in which there is a 1 minute gap in between events - during this minute, the&amp;nbsp;&lt;em&gt;timeout&lt;/em&gt; variable will not change at all, since the device will&amp;nbsp; be waiting for an event to occur.&lt;/p&gt;
[quote user="polimarte "]What do you mean with something else? What you suggest me is to use a flag in case of NACK and restart the transition, is it correct?&amp;nbsp;[/quote]
&lt;p&gt;Yes, and then have something else ( such as a retransmit ) happen if the NACK flag is set. So, the function waits for either twi_*x_done to be set, and then proceed with the function, or for another flag&amp;nbsp;&lt;em&gt;twi_*x_failed&lt;/em&gt; to be set, in which case it aborts the remaining part of the &amp;quot;readByte&amp;quot; function, and either tries again, or resolves the NACK issue in some other way.&lt;/p&gt;
[quote user="polimarte "]This is a thing that really i don&amp;#39;t understand, as you can see from the screenshot of the Debugger&amp;nbsp; i don&amp;#39;t receive any err_code. It gives me NRF_SUCCESS.[/quote]
&lt;p&gt;It is not so easy for me to get a good understanding of exactly what is happening from screenshots, but yes, I see that the variable is 0, indicating success. Apart from the screenshot you should see a debug output if anything else than NRF_SUCCESS was returned.&amp;nbsp;&lt;/p&gt;
[quote user="polimarte "]So without the loop waiting for the &lt;span&gt;NRFX_TWIM_EVT_DONE&lt;/span&gt; my code run over the transition without stopping at the CHECK. What am i missing here?&amp;nbsp;[/quote]
&lt;p&gt;This is correct, and with the current implementation this is as expected - since the nrfx_xfer function is non-blocking, it will return before the slave device has had the chance to NACK ( or otherwise misbehave ). Therefore, you will have to add some kind of wait in between the two calls.&lt;br /&gt;If you were to change your implementation of this, you could split the function into multiple parts, that start a timer when they conclude - and when this delay timer expires, it checks if the previous transfer was successful - and then uses the result of this check to either proceeds with the transactions, or retransmit.&lt;/p&gt;
[quote user="polimarte "]I don&amp;#39;t have further expanation on the datasheet about how the handle NACK events unfortunately.[/quote]
&lt;p&gt;I did a quick search for the part number&amp;nbsp;&lt;a href="https://pdfserv.maximintegrated.com/en/an/user-guide-6806-max32664.pdf"&gt;MAX32664 and found this datasheet&lt;/a&gt;. Is this the part you are working with?&lt;br /&gt;Please take a look at page 18 and 19, as they give a more detailed, plain-text, description of both a read and a write sequence.&lt;br /&gt;Among other things, it describes that the device needs a given CMD_DELAY to ready data for transfer - this could for example lead the device to NACK a request, since it is not yet ready to proceed with a transfer.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/277191?ContentTypeID=1</link><pubDate>Tue, 27 Oct 2020 15:20:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7ec81dd6-73a6-4f48-94f2-e6edb749a854</guid><dc:creator>polimarte </dc:creator><description>&lt;p&gt;Hi Karl!&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277054#277054"]are you content with using the RTT viewer? [/quote]
&lt;p&gt;That&amp;#39;s fine, i will continue to work with RTT viewer.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277054#277054"]Alternatively, you could also add a timer that only lets your while-loops run for so long.[/quote]
&lt;p&gt;I have modified my code with a timer in this way, introducing a timeout:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t readByte( uint8_t familyByte, uint8_t indexByte)
{
        uint32_t timeout = OXI_TWI_TIMEOUT;
		nrfx_err_t err_code;

		uint8_t StatusByte;    
        uint8_t ReturnByte;
   
        uint8_t rx_buffer[2];
		size_t rx_lenght =2;

		uint8_t tx_buffer[] = {familyByte, indexByte};    
		size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte);

		nrfx_twim_xfer_desc_t tx_xfer = NRFX_TWIM_XFER_DESC_TX(OXI_ADDRESS_W, tx_buffer, tx_lenght);
		err_code = nrfx_twim_xfer(&amp;amp;twim_instance, &amp;amp;tx_xfer, 0);
		APP_ERROR_CHECK(err_code);
		
		while((!twim_tx_done) &amp;amp;&amp;amp; --timeout)
        {
            __WFE();
        } 
		if(!timeout) err_code=NRF_ERROR_TIMEOUT;
		else  twim_tx_done  = false;
		APP_ERROR_CHECK(err_code);
 

		nrfx_twim_xfer_desc_t rx_xfer = NRFX_TWIM_XFER_DESC_RX(OXI_ADDRESS_R, rx_buffer, rx_lenght);
		err_code = nrfx_twim_xfer(&amp;amp;twim_instance, &amp;amp;rx_xfer, 0);
		APP_ERROR_CHECK(err_code);
	
        while((!twim_rx_done) &amp;amp;&amp;amp; --timeout)
        {
            __WFE();
        } 
		if(!timeout) err_code=NRF_ERROR_TIMEOUT;
		else  twim_rx_done  = false;
		APP_ERROR_CHECK(err_code);
  
	
		StatusByte = rx_buffer[0];
        NRF_LOG_INFO(&amp;quot;Status Byte: %lu \n&amp;quot;,StatusByte);
    
		ReturnByte = rx_buffer[1];  
		return ReturnByte;
}&lt;/pre&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277054#277054"]I think the easiest fix ( but not prettiest) to this problem would be to just add another variable that is set if the transaction failed, and then tries it again or does something else.[/quote]
&lt;p&gt;What do you mean with something else? What you suggest me is to use a flag in case of NACK and restart the transition, is it correct?&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277054#277054"]Is your APP_ERROR_CHECK on line 16 of readByte returning any errors?[/quote]
&lt;p&gt;This is a thing that really i don&amp;#39;t understand, as you can see from the screenshot of the Debugger&amp;nbsp; i don&amp;#39;t receive any err_code. It gives me NRF_SUCCESS. So without the loop waiting for the &lt;span&gt;NRFX_TWIM_EVT_DONE&lt;/span&gt; my code run over the transition without stopping at the CHECK. What am i missing here?&amp;nbsp;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/277054#277054"]We should also look into why the address is returning a NACK.[/quote]
&lt;p&gt;As you can see here in the first lines:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/6278.Screenshot-_2800_98_2900_.png" /&gt;&lt;/p&gt;
&lt;p&gt;it&amp;#39;s said: &amp;quot;The MAX32664 uses 0xAA as the I2C 8-bit slave write address and 0xAB is used as the I2C 8-bit slave read address&amp;quot; and than in the following pages &amp;quot;The eight bits to be transferred as a slave address for the MAX32664 is 0xAA for a write transaction&amp;quot;. So i am using different slave adresses for the TX (0xAA) and the RX(0xAB) as indicated. Am i wrong about this? I don&amp;#39;t have further expanation on the datasheet about how the handle NACK events unfortunately.&lt;/p&gt;
&lt;p&gt;Thanks for your help!&lt;/p&gt;
&lt;p&gt;Polimarte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/277054?ContentTypeID=1</link><pubDate>Tue, 27 Oct 2020 08:59:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:167febef-7842-4a26-b831-fe35204ccb32</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hi Polimarte,&lt;/p&gt;
[quote user="polimarte "]it is a pleasure to hear you again![/quote]
&lt;p&gt;Likewise! It is great to see you progress with your application!&amp;nbsp;&lt;/p&gt;
[quote user="polimarte "]I have to admit that i found some problems in enabling the log uart in the last SDK so i am using the&amp;nbsp;&lt;span&gt;RTT viewer but nothing happen on my RTT terminal if i&amp;nbsp;am stack&amp;nbsp;in a loop as in my case.&lt;/span&gt;[/quote]
&lt;p&gt;I understand. Is this something you would like to look into also, or are you content with using the RTT viewer? RTT is just as good a backend for the logger as UART, by the way, it is just that it requires an RTT compatible terminal.&lt;/p&gt;
[quote user="polimarte "]&lt;p&gt;My code is stack at the loop for twim_tx_done, so&amp;nbsp;NRFX_TWIM_EVT_DONE is never set.&lt;/p&gt;
&lt;p&gt;If i comment these loop on both the Read/Write Bytes functions on my window, my code run without block and i can see this on the RTT viewer:&lt;/p&gt;[/quote][quote user="polimarte "]Yes i can enter on the twim_handler and as i can see from the RTT viewer i get :&amp;nbsp;NRFX_TWIM_EVT_ADDRESS_NACK.[/quote]
&lt;p&gt;From your code, I would expect this behavior. Looking at your read and write function, they do not account for the possibility that you may receive an error.&lt;br /&gt;In essence, if you call readByte now, it will go into the while-loops, and wait for the DONE event to let it exit the waiting. If instead an TWIM error is received, then the error event is generated, and twim_*x_done is never set. Since the transaction failed, and is not restarted, the twim_*x_done will never be set, and you will be stuck in the loop forever.&lt;br /&gt;&lt;br /&gt;I think the easiest fix ( but not prettiest) to this problem would be to just add another variable that is set if the transaction failed, and then tries it again or does something else. Alternatively, you could also add a timer that only lets your while-loops run for so long. Is your APP_ERROR_CHECK on line 16 of readByte returning any errors?&lt;br /&gt;&lt;br /&gt;We should also look into why the address is returning a NACK. What does the datasheet for your sensor say, what is the possible reasons for the device to NACK the address?&lt;/p&gt;
[quote user="polimarte "]Yes, i do. I am using KEIL. Unfortunately i m still studying how to setup the logic analyzer because i am not able to let it work properly (i am getting always &amp;quot;Unknown Signal&amp;quot;).[/quote]
&lt;p&gt;I see. It is a great tool to have available when working with serial protocols, since this would uncover any unexpected behavior on the lines.&lt;br /&gt;I think the current problem lays in the code - which we will continue debug - but for future debugging it would be great to have the logic analyzer up and running.&lt;/p&gt;
[quote user="polimarte "]Mange Takk Karl![/quote]
&lt;p&gt;Prego, Polimarte! :)&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/276949?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2020 15:41:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b635678f-0bcf-4fbd-b79d-a8ef9f6a3125</guid><dc:creator>polimarte </dc:creator><description>&lt;p&gt;Hi Karl, it is a pleasure to hear you again!&lt;/p&gt;
&lt;p&gt;I have to admit that i found some problems in enabling the log uart in the last SDK so i am using the&amp;nbsp;&lt;span&gt;RTT viewer but nothing happen on my RTT terminal if i&amp;nbsp;am stack&amp;nbsp;in a loop as in my case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;My code is stack at the loop for twim_tx_done, so&amp;nbsp;NRFX_TWIM_EVT_DONE is never set.&lt;/p&gt;
&lt;p&gt;If i comment these loop on both the Read/Write Bytes functions on my window, my code run without block and i can see this on the RTT viewer:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/Screenshot-_2800_96_2900_.png" /&gt;&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/276930#276930"]Are you ever entering your twim_handler?[/quote]
&lt;p&gt;Yes i can enter on the twim_handler and as i can see from the RTT viewer i get :&amp;nbsp;NRFX_TWIM_EVT_ADDRESS_NACK.&lt;/p&gt;
[quote userid="87869" url="~/f/nordic-q-a/67577/twi-transaction-failed/276930#276930"]Do you have access to a logic analyzer, so you may see what is happening on the pins themselves?&amp;nbsp;[/quote]
&lt;p&gt;Yes, i do. I am using KEIL. Unfortunately i m still studying how to setup the logic analyzer because i am not able to let it work properly (i am getting always &amp;quot;Unknown Signal&amp;quot;).&lt;/p&gt;
&lt;p&gt;Mange Takk Karl!&lt;/p&gt;
&lt;p&gt;polimarte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: TWI transaction failed</title><link>https://devzone.nordicsemi.com/thread/276930?ContentTypeID=1</link><pubDate>Mon, 26 Oct 2020 14:59:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcdb980f-6d4c-4d4d-bcda-cca654a952fd</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Polimarte!&lt;br /&gt;&lt;br /&gt;From your included screenshot you seem to be encountering some errors. Is this correct? Which errors are these, and where do they come from?&lt;br /&gt;&lt;br /&gt;Are you ever entering your twim_handler?&lt;/p&gt;
[quote user=""]No task is started and no byte is transferred.[/quote]
&lt;p&gt;Do you have access to a logic analyzer, so you may see what is happening on the pins themselves?&amp;nbsp;&lt;/p&gt;
[quote user=""]I don&amp;#39;t receive any error (err_code always 0 (NRF_SUCCESS)) but it seems that after the first transaction (TX) nothing happen as i can see from the TWIM0 window:[/quote][quote user=""]No task is started and no byte is transferred.[/quote]
&lt;p&gt;Please elaborate where you are reading this. From what I can see in your screenshot, both ERROR and TXSTARTED is true - leading me to believe that a TX in fact is started, and an error is returned somewhere.&lt;br /&gt;Let us start by finding the source of this error, so we may get to the bottom of why this is not working as expected.&lt;br /&gt;&lt;br /&gt;Looking forward to resolving this issue together!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>