<?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 Read transfer doesn&amp;#39;t happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76826/i2c-read-transfer-doesn-t-happen-with-ultasknotifytake</link><description>I am using nrf_drv_twi_rx to initiate an I2C read transfer but the interrupt isn&amp;#39;t fired for the RX transfer when the ulTaskNotifyTake is used, but seems to work without ulTaskNotifyTake() call. When I hooked up to the logic analyzer, it seems the read</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Jul 2021 04:09:56 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76826/i2c-read-transfer-doesn-t-happen-with-ultasknotifytake" /><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/319921?ContentTypeID=1</link><pubDate>Wed, 14 Jul 2021 04:09:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f22eded-e00a-41f5-a759-59514fd23e34</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;let&amp;#39;s follow up on -&amp;gt;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/77459/twi-driver-remains-busy-right-after-the-nrf_drv_twi_tx-even-though-tx-transfer-is-completed"&gt;devzone.nordicsemi.com/.../twi-driver-remains-busy-right-after-the-nrf_drv_twi_tx-even-though-tx-transfer-is-completed&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/319696?ContentTypeID=1</link><pubDate>Tue, 13 Jul 2021 04:42:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f7c0c8f-69b4-49cd-a7a5-2fc7bfd7527a</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;I also added a simple GPIO write function call after the read function and the gpio write was successful but the read function still doesn&amp;#39;t seem to fully execute i.e don&amp;#39;t see read bytes being sent in the logic analyzer. Can you confirm if the&amp;nbsp;nrf_drv_twi_rx() isn&amp;#39;t causing any trouble? (i doubt though but still)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/319499?ContentTypeID=1</link><pubDate>Mon, 12 Jul 2021 01:35:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33367318-f69a-4353-a3bd-b4f5acfa50cf</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;&lt;span&gt;&lt;strong&gt;processData()&lt;/strong&gt; is mainly just using the raw sensor data to generate an appropriate output value. If you bail out from the function itself, don&amp;#39;t you think you&amp;#39;d be most likely to lose the data as opposed to only processing once you know there&amp;#39;s something to process?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Also when I put the breakpoints inside the nrf_drv_twi_rx(), and run in the debug mode, I see things running in an expected manner, and if I don&amp;#39;t put breakpoints, and I have xTaskNotifyTake(),&amp;nbsp;&lt;strong&gt;initiateI2cRead()&amp;nbsp;&lt;/strong&gt;doesn&amp;#39;t get fully executed hence no interrupt generation.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And you&amp;#39;re right about using&amp;nbsp;&lt;strong&gt;portYIELD_FROM_ISR&lt;/strong&gt;() inside the ISR but that&amp;#39;s not the solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/319333?ContentTypeID=1</link><pubDate>Fri, 09 Jul 2021 11:03:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8973df83-ff13-4cb4-9ab4-a5333eacbadd</guid><dc:creator>Susheel Nuguru</dc:creator><description>[quote user="morpho"]&lt;span&gt;If I&amp;#39;m understanding correctly, above is the flow. If that&amp;#39;s true, don&amp;#39;t you think you&amp;#39;re missing out the processing of certain reads in case data wasn&amp;#39;t read by the time processData() was invoked?&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;[/quote]
&lt;p&gt;&amp;nbsp;I can&amp;#39;t see the implementation of processData(). Normally if there is no data available, then the implementation of processData should be able to detect that there is no new data and bails out early.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you are very confident that you do not need such early bailout mechanism and also you are sure that this function&amp;#39;s global data is being protected using some critical sections, then I would not look into this direction. Lets try to focus more on the visible code you provided.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
	            vTaskNotifyGiveFromISR(obj-&amp;gt;taskHandle, pdFALSE);
	            
            }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;try notification from the ISR this way.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    BaseType_t yield_req = pdFALSE;

            case NRF_DRV_TWI_EVT_DONE:
            if (p_event-&amp;gt;xfer_desc.type == NRF_DRV_TWI_XFER_RX)
            {
                vTaskNotifyGiveFromISR(obj-&amp;gt;taskHandle, &amp;amp;yield_req);

                /* Switch the task if required. */
                portYIELD_FROM_ISR(yield_req);
            }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/319053?ContentTypeID=1</link><pubDate>Thu, 08 Jul 2021 04:38:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:15a156e9-116a-4e7c-b7a2-65a03ee1e8e0</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Thanks for the response.&amp;nbsp;&lt;br /&gt;sorry, I&amp;#39;m still not fully convinced as to why would processData() be still after ulTaskNotifyTake. Isn&amp;#39;t the main idea behind&amp;nbsp;&lt;span&gt;ulTaskNotifyTake to block the current task till data is ready to be processed? Perhaps why even go inside processData() if there&amp;#39;s nothing to process, plus what are you blocking the test after processData() via ulTaskNotifyTake&amp;nbsp;for?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;if this is the flow, and assuming processData() doesn&amp;#39;t do anything if there&amp;#39;s no data, I assume the following flow:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- interrupt is enabled but data hasn&amp;#39;t been read yet&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- processData() is invoked but nothing to process&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- block the task till the&amp;nbsp;I2C data is fully read. Unblock it once the data is read but it&amp;#39;s not processed&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;- repeat the loop --&amp;gt; go on to read the next i2c data&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If I&amp;#39;m understanding correctly, above is the flow. If that&amp;#39;s true, don&amp;#39;t you think you&amp;#39;re missing out the processing of certain reads in case data wasn&amp;#39;t read by the time processData() was invoked?&lt;/span&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;while(true)&lt;br /&gt; { &lt;br /&gt; initiateI2cRead();&lt;/p&gt;
&lt;p&gt;processData();&lt;/p&gt;
&lt;p&gt;uint32_t taskNotify = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);&lt;br /&gt;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/318726?ContentTypeID=1</link><pubDate>Tue, 06 Jul 2021 07:31:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3b84f29-6124-4af9-8d1d-c415e7a78a27</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Sorry for late response morpho.&lt;/p&gt;
&lt;p&gt;Normally processData should do nothing if there is no data (it is normally waste of cpu time the first call) but it avoids one race condition when your application state machine depends on process data to complete for preparing for the next transaction.&lt;/p&gt;
&lt;p&gt;I would still recommend you to have process data first and call&amp;nbsp;&lt;span&gt;ulTaskNotifyTake&amp;nbsp;. It would only make difference the first call. Then it would be a loop like how you have it now (minus the race condition possibility)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/318488?ContentTypeID=1</link><pubDate>Fri, 02 Jul 2021 17:20:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8f065f19-3c43-462e-845f-fb8d962d9c8e</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Any idea Susheel?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/318018?ContentTypeID=1</link><pubDate>Wed, 30 Jun 2021 14:17:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f88cb5e0-89fb-4742-9166-0bedafad4f2f</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Wouldn&amp;#39;t it make more sense to process the data after it&amp;#39;s been signalled from the interrupt rather than spinwaiting till the data is ready to be processed first? That was the point I decided to use&amp;nbsp;&lt;span&gt;ulTaskNotifyTake so the task is blocked till the data is received, and processed only after&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/317929?ContentTypeID=1</link><pubDate>Wed, 30 Jun 2021 10:48:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d155e617-e0ad-4700-9da4-749ee80df902</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;seems like your app&amp;#39;s state machine is stuck at&amp;nbsp;ulTaskNotifyTake. Probably best to have&amp;nbsp;ulTaskNotifyTake after processData() to kick off the send/receive properly and then wait for the events?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/317547?ContentTypeID=1</link><pubDate>Mon, 28 Jun 2021 16:07:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8afe172e-c0f9-4c1e-8953-b8497fb11828</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;sorry, the&amp;nbsp;init function isnt shown. As mentioned, it works without the ulTaskNotifyTake, which should&amp;rsquo;ve hinted at init function is&amp;nbsp;indeed invoked&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read transfer doesn't happen with ulTaskNotifyTake</title><link>https://devzone.nordicsemi.com/thread/317400?ContentTypeID=1</link><pubDate>Mon, 28 Jun 2021 08:16:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e813821-657c-4e31-aacc-d55de7f37bd5</guid><dc:creator>Andre</dc:creator><description>&lt;p&gt;You need to initialise the twi peripheral using&amp;nbsp;nrf_drv_twi_init() before you can call nrf_drv_twi_rx()&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>