<?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/Write functions in GPIO Interrupt</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/105170/i2c-read-write-functions-in-gpio-interrupt</link><description>Hi. 
 I&amp;#39;ve configured an I2C device to gather data and if finished it will trigger an interrupt line which I connected to the an GPIO interrupt of the NRF52. I&amp;#39;m using i2c_burst_read(...) from within that GPIO interrupt but always get the following error</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 30 Oct 2023 12:10:33 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/105170/i2c-read-write-functions-in-gpio-interrupt" /><item><title>RE: I2C Read/Write functions in GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/453017?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 12:10:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d93f00fc-b792-4d20-bf0a-01ba6f336ff1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Happy to help. Yes, it seems that k_event_* might be more suitable for your situation. The&amp;nbsp;main reason I suggested using a semaphore was its simplicity. However, there are several options available to signal an event from the ISR to your thread.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read/Write functions in GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/452997?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 11:11:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4483b2b9-0f81-4fce-ae84-7e6a42295f27</guid><dc:creator>Phobios</dc:creator><description>&lt;p&gt;Thanks a lot Vidar for the clarification.&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve a thread anyway, since I have some other heavy duty work to do there so I think I&amp;#39;ll go with that. Since I have two ISR GPIO lines, aka two interrupts I&amp;#39;m using&amp;nbsp;&lt;span class="n"&gt;k_event_post() and k_event_wait() instead of semaphores. Then I can distinguish which event has occurred. Is there any downside using this; should I go with the semaphore or is it anyway the same procedure in the SDK background (from timing, awake time and battery aspects)&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: I2C Read/Write functions in GPIO Interrupt</title><link>https://devzone.nordicsemi.com/thread/452991?ContentTypeID=1</link><pubDate>Mon, 30 Oct 2023 10:44:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69c3dbc6-f81c-4f6a-994e-3c7f4bf63abb</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;Phobios,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]But would&amp;#39;t that be way slower that just reading a few registers within the ISR[/quote]
&lt;p&gt;The API initiates the read transaction and doesn&amp;#39;t return until the transaction completes, making it more involved than reading some registers. As a result, the blocking time can be relatively long.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The i2c driver is using semaphores with&amp;nbsp;waits to allow the API to be blocking/synchronous, and these cannot be called from an interrupt context.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
[quote user=""]How would be the solution to this? I was thinking of using an event which i set in the GPIO interrupt and in a thread I read out the data with I2C functions[/quote]
&lt;p&gt;If you create a separate thread, you can use&amp;nbsp;k_sem_give() from the gpio interrupt to wake-up this thread and perform the burst read. Alternatively, you can create a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/services/threads/workqueue.html#workqueue-threads"&gt;workqueue&lt;/a&gt; item to read the sensor.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>