<?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>I2C clock stop issue</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97075/i2c-clock-stop-issue</link><description>I am working on a project where my nRF5340 is a Master and communicate to the slave device over I2C. 
 The I2C is implemented in secure-partition application and I observe the clock is stopped after I2C read operation. No matter I trigger STOP/SUSPEND</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Apr 2023 10:51:23 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97075/i2c-clock-stop-issue" /><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/419022?ContentTypeID=1</link><pubDate>Tue, 04 Apr 2023 10:51:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3156f6c4-5081-40a3-976a-faba5cdee553</guid><dc:creator>Jithin A</dc:creator><description>&lt;p&gt;Thank you Kenneth for the reference.&lt;/p&gt;
&lt;p&gt;I now find the issue and fixed it.&lt;/p&gt;
&lt;p&gt;The issue is with the STOP task.&lt;/p&gt;
&lt;p&gt;Earlier I was only waiting for the write/read task to complete and not stopping the TWIM which is still running. Now after reading the TWIM operation carefully I noticed I need to call STOP task to STOP the TWIM operation which I was not doing on my end.&lt;/p&gt;
&lt;p&gt;Below is the fixed code&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void
twim_write (const uint8_t *p_buf, size_t len)
{
    //
    // Stop previous session if any
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STOP);

    //
    // Prepare for the new session
    //
	nrf_twim_tx_buffer_set(NRF_TWIM1, p_buf, len);
    nrf_twim_rx_buffer_set(NRF_TWIM1, NULL, 0);
	nrf_twim_address_set(NRF_TWIM1, DEV_I2C_ADDR);

    //
    // Start tx task
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STARTTX);

    //
    // Wait until the transmission is complete, clear the event on complete
    //
	while(!nrf_twim_event_check(NRF_TWIM1, NRF_TWIM_EVENT_LASTTX));
	nrf_twim_event_clear(NRF_TWIM1, NRF_TWIM_EVENT_LASTTX);

    //
    // Write task is complete, STOP the session
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STOP);
}

void
twim_read (uint8_t *p_buf, size_t len)
{
    //
    // Stop previous session if any
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STOP);

    //
    // Prepare for the new session
    //
	nrf_twim_tx_buffer_set(NRF_TWIM1, NULL, 0);
    nrf_twim_rx_buffer_set(NRF_TWIM1, p_buf, len);
	nrf_twim_address_set(NRF_TWIM1, DEV_I2C_ADDR);

    //
    // Start rx task
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STARTRX);

    //
    // Wait until the reception is complete, clear the event on complete
    //
	while(!nrf_twim_event_check(NRF_TWIM1, NRF_TWIM_EVENT_LASTRX));
	nrf_twim_event_clear(NRF_TWIM1, NRF_TWIM_EVENT_LASTRX);

    //
    // Read task is complete, STOP the session
    //
	nrf_twim_task_trigger(NRF_TWIM1, NRF_TWIM_TASK_STOP);
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/418995?ContentTypeID=1</link><pubDate>Tue, 04 Apr 2023 09:25:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17b94c1a-cbb8-4c2b-8c62-6f8efdb73386</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I suggest to look at the datasheet on the TWIM peripheral:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/twim.html"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/twim.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;There are several figures there that may be helpful.&lt;/p&gt;
&lt;p&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/418957?ContentTypeID=1</link><pubDate>Tue, 04 Apr 2023 07:46:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a468f63-6f53-4ae2-8fdb-88a7a377bf09</guid><dc:creator>Jithin A</dc:creator><description>&lt;p&gt;Hi, sorry for the delayed response.&lt;/p&gt;
&lt;p&gt;I was working on another high priority task for which I could not see to this taks.&lt;/p&gt;
&lt;p&gt;Let me explain my findings:&lt;/p&gt;
&lt;p&gt;I see I can not use Zephyr RTOS in secure (TF-M) application image and this force me to use nrf lib for TWI(I2C) implementation.&lt;/p&gt;
&lt;p&gt;I did not find any suitable example for implementing I2C in secure (TF-M) application image.&lt;/p&gt;
&lt;p&gt;After doing some R&amp;amp;D on I2C I ended up with the above implementation which uses nrf lib for TWI using DMA.&lt;/p&gt;
&lt;p&gt;I see clock on SCL even after I get NRF_TWIM_EVENT_LASTRX event.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll be active for this case from now as all my high priority tasks are complete.&lt;/p&gt;
&lt;p&gt;Please guide me to any available example or correct me if I am doing anything wrong.&lt;/p&gt;
&lt;p&gt;Thank you in advance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/412512?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2023 13:04:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:19305994-4db5-4ae5-bb45-b7d8fffbd79f</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I am not entirely sure what is failing here, you are working very low level.&lt;/p&gt;
&lt;p&gt;First of all make sure you have read the TWIM chapter:&lt;br /&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/twim.html"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/twim.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Secondly I suggest to try to use the&amp;nbsp;i2c_nrfx_twim_transfer()-&amp;gt;twim_xfer() to setup and execute transfer, instead of the manual setup of buffers, events and tasks. If you still want to handle buffers, events and tasks manually, then look at the implementation of&amp;nbsp;&lt;span&gt;i2c_nrfx_twim_transfer()&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;What is the state of the SDA line here when SCL is low?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenenth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/412388?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2023 02:24:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fe89ee09-6d10-4ffc-a3e5-535ee4f2c101</guid><dc:creator>Jithin A</dc:creator><description>&lt;p&gt;Thank you, please let me know ASAP&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/412351?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 18:52:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c42affd0-e059-496b-a57e-001185716044</guid><dc:creator>Kazi Afroza Sultana</dc:creator><description>&lt;p&gt;Hello,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am looking into few issues regarding this. I will reply you tomorrow.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kazi&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C clock stop issue</title><link>https://devzone.nordicsemi.com/thread/412202?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 09:43:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5824e431-c4dd-4e7f-81ef-74168ef92bd0</guid><dc:creator>Jithin A</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Anyone please help me with this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>