<?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>Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/114508/suspending-a-thread-also-blocks-i2c</link><description>Hello, 
 
 I have a thread that is reading sensor data over I2C. When I suspend it I cant access I2C from another thread that&amp;#39;s reading another I2C device. 
 I tried isolating the I2C read function with mutex so only one device can access it at a time</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Oct 2024 05:34:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/114508/suspending-a-thread-also-blocks-i2c" /><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/505808?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2024 05:34:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25b77040-9e31-43ae-bcf7-98dd14e7e846</guid><dc:creator>IvanR</dc:creator><description>&lt;p&gt;Solved it by using semaphore to pause the thread instead of suspending.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    // Check if the thread should be paused
    if (k_sem_count_get(&amp;amp;gyro_thread_sem) == 1) {
      // Wait on the semaphore if a pause is requested
      k_sem_take(&amp;amp;gyro_thread_sem, K_FOREVER);
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/502505?ContentTypeID=1</link><pubDate>Fri, 13 Sep 2024 13:50:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:22c1f3bb-a0d4-4962-99a5-636a93f81a22</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I understand very little of this. None of the names from this list matches anything that you posted in the earlier snippets. Perhaps you can upload the entire application, and let me know what file and line number things stop working?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/502428?ContentTypeID=1</link><pubDate>Fri, 13 Sep 2024 06:29:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bcfb73e7-6054-496a-8996-f3c3b4f1c3b9</guid><dc:creator>IvanR</dc:creator><description>&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void suspendThreads(struct k_thread* notifThread, struct k_thread* gyroThread, struct k_thread* adcThread) {
  k_thread_suspend(notifThread);
  k_thread_suspend(gyroThread);
  adc_thread_pause = true;
  // Wait a short period to ensure the ADC thread has paused corectly
  k_sleep(K_MSEC(200));
  k_thread_suspend(adcThread);
  k_timer_stop(&amp;amp;notification_timer);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/502391?ContentTypeID=1</link><pubDate>Thu, 12 Sep 2024 21:29:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:38c9b463-c7d8-4a8c-aa6d-3da3e3fccb40</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;What exactly do you mean by suspending the thread? How do you do it? Can you please share some snippets?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/501747?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2024 12:57:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f2b8dac2-98d9-4107-808b-ada0e89c99aa</guid><dc:creator>IvanR</dc:creator><description>&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span&gt;readSensorData&amp;nbsp; works fine, I can suspend it and resume it and it works, that part is not an issue. But when I suspend the thread thats reading it.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;readSensorData is read from thread get_Gyro within while(1). I need that data as fast as LSM can provide.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;if I suspend that thread I cant access I2C from main thread that (with issued command) reads RTC. If I unsuspend getGyro thread I can read the RTC.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/501688?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2024 10:07:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecf79a72-4fde-4e26-8b40-f01bf78e02f3</guid><dc:creator>Edvin</dc:creator><description>[quote user="IvanR"]without success.[/quote]
&lt;p&gt;What does that mean? Does readSensorData() return anything other than 0?&lt;/p&gt;
[quote user="IvanR"]When I suspent that thread and try to read RTC the entire device hangs without any errors[/quote]
&lt;p&gt;Where does it hang? Do you have any other threads? Are they still running?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;From where are you calling readSensorData? From main()? From an interrupt (timer, perhaps)?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/501651?ContentTypeID=1</link><pubDate>Mon, 09 Sep 2024 07:30:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8cea4d7-b820-4186-af3a-6423d5c25c53</guid><dc:creator>IvanR</dc:creator><description>&lt;p&gt;code is part of huge project.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have two I2C devices connected.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;One is Accelerometar&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;&lt;span&gt;const&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;i2c_dt_spec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;spec&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .&lt;/span&gt;&lt;span&gt;bus&lt;/span&gt;&lt;span&gt; &amp;nbsp;&lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;dev_I2C&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .&lt;/span&gt;&lt;span&gt;addr&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0x&lt;/span&gt;&lt;span&gt;6A&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; };&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;other is RTC&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;const struct i2c_dt_spec spec_rtc = {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;.bus &amp;nbsp;= dev_I2C,&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp;.addr = 0x68&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;Accelerometar is beeing read in its thread by calling&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;static inline int readSensorData(int16_t* acceleration, int16_t* angular_rate) {
&amp;#160; // unsigned int key;

&amp;#160; // k_mutex_lock(&amp;amp;i2c_access_mutex, K_FOREVER);
&amp;#160; // key = irq_lock();

&amp;#160; int err = lsm6dso_acceleration_raw_get(gdev, acceleration);
&amp;#160; if (err) {
&amp;#160; &amp;#160; printf(&amp;quot;Error reading acceleration: %d\n&amp;quot;, err);
&amp;#160; &amp;#160; return err;
&amp;#160; }

&amp;#160; err = lsm6dso_angular_rate_raw_get(gdev, angular_rate);
&amp;#160; if (err) {
&amp;#160; &amp;#160; printf(&amp;quot;Error reading gyroscope: %d\n&amp;quot;, err);
&amp;#160; &amp;#160; return err;
&amp;#160; }

&amp;#160; // irq_unlock(key);
&amp;#160; // k_mutex_unlock(&amp;amp;i2c_access_mutex);
&amp;#160; return 0;
}
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;without success. When I suspent that thread and try to read RTC the entire device hangs without any errors.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Suspending a thread also blocks I2C</title><link>https://devzone.nordicsemi.com/thread/501564?ContentTypeID=1</link><pubDate>Fri, 06 Sep 2024 13:46:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fbcb7e6-73f5-4596-b959-c1ce331c95f5</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Can you please share some snippets showing the issue? Or perhaps an application that I can build and run on a DK to replicate the issue?&lt;/p&gt;
&lt;p&gt;Are you finished reading the I2C before going to sleep? Or were you interrupted by another thread?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>