<?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>Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/96625/continuous-background-i2c-process</link><description>Hi Nordic, 
 We are migrating an older mesh project from nrfSDK 17 to zephyr and have a question about what is the BEST way to have a continuous I2C process running in zephyr. The application has 3 mesh models, uses 2 PWM modules, ADC reads every roughly</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 01 Mar 2023 17:19:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/96625/continuous-background-i2c-process" /><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/412822?ContentTypeID=1</link><pubDate>Wed, 01 Mar 2023 17:19:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5c2bbb13-cbd9-4229-a7f2-cd0113dec733</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I believe you can&amp;#39;t trigger I2C transfers via PPI&amp;nbsp;with zephyr&amp;#39;s I2C API, but you can if you use the nrfx driver directly&amp;nbsp;if you set up transfers by calling&amp;nbsp;twim_xfer() with the&amp;nbsp;NRFX_TWIM_FLAG_REPEATED_XFER flag set.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/412315?ContentTypeID=1</link><pubDate>Mon, 27 Feb 2023 15:02:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd24e8e7-aa14-44e1-9fda-5065ee8d702d</guid><dc:creator>mneber</dc:creator><description>&lt;p&gt;Thank you Haakonsh,&lt;/p&gt;
&lt;p&gt;That gives us a good place to start from. Are there any benefit to using PPI to connect the timer to trigger the i2c read? I was thinking no in this case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/411157?ContentTypeID=1</link><pubDate>Tue, 21 Feb 2023 15:02:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9215c9ba-fb44-4743-ad44-ad6e4a244728</guid><dc:creator>haakonsh</dc:creator><description>[quote user="mneber"]The metairq sample uses a resetting z_add_timeout()&amp;nbsp;for the timer. Is this ok to use system timer&amp;nbsp;or do we need to &amp;nbsp;look at a different timer module that can be&amp;nbsp;setup to run in background?[/quote]
&lt;p&gt;I think you&amp;nbsp;might want to use a TIMER peripheral for this application, as the 32.768kHz system timer will have at best 0.0 - 30.51us resolution. Though you can always try it with the system timer, i think you will be able to spot issues if you are aware of they can manifest.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;See&amp;nbsp;modules\hal\nordic\nrfx\samples\src\nrfx_timer\timer\README.md&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/410980?ContentTypeID=1</link><pubDate>Mon, 20 Feb 2023 23:50:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:936fe97a-db59-4b99-9382-39e646d1f25f</guid><dc:creator>haakonsh</dc:creator><description>[quote user="mneber"]A basic master repeat start sequence is good for us, in our application we write 1&amp;nbsp;byte to&amp;nbsp;read 6 bytes. Is i2c_read() from i2c.h in the zephyr library sufficient for us?&amp;nbsp;[/quote]
&lt;p&gt;Yes I believe so.&lt;/p&gt;
[quote user="mneber"]How do we know when the transfer has completed?[/quote]
&lt;p&gt;i2c_read() is synchronous, it will return 0&amp;nbsp;if the transfer has completed successfully.&amp;nbsp;&lt;/p&gt;
[quote user="mneber"]The metairq sample uses a resetting z_add_timeout()&amp;nbsp;for the timer. Is this ok to use system timer&amp;nbsp;or do we need to &amp;nbsp;look at a different timer module that can be&amp;nbsp;setup to run in background?[/quote]
&lt;p&gt;I&amp;#39;ll get back to you&amp;nbsp;regarding this question asap.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/410882?ContentTypeID=1</link><pubDate>Mon, 20 Feb 2023 12:54:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:65170b98-8937-4b9e-bc9f-4323acef1fd3</guid><dc:creator>mneber</dc:creator><description>&lt;p&gt;Hi Haakonsh,&lt;/p&gt;
&lt;p&gt;Thank you for your insightful reply. From researching your comments I think the direction we want to go is using a TIMER to trigger transfers. Reading i2c data at a consistent cadence is important.&lt;/p&gt;
&lt;p&gt;I like the idea of batch processing samples. Processing the read data is less important. I think we want to&amp;nbsp;run timed i2C reads from the&amp;nbsp;main thread and queue the read data in their own thread for processing? This makes good sense to me.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for pointing out&amp;nbsp;the metairq sample, we will adapt to use&amp;nbsp;as a tool to measure latency within our processing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A couple more questions on I2C and timer in Zephyr:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;A basic master repeat start sequence is good for us, in our application we write 1&amp;nbsp;byte to&amp;nbsp;read 6 bytes. Is i2c_read() from i2c.h in the zephyr library sufficient for us?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For processing we want to call k_msgq_put() with the read data shortly after i2c_read(). How do we know when the transfer has completed? When we did this with the nrfx library using&amp;nbsp;nrfx_twim_rx() there is an event handler that flags when the transfer completes. We use this handler to move the data into processing.&amp;nbsp;I don&amp;#39;t think I see an event handler in the zephyr i2c.h library. Do we need to register a handler to capture that event somehow?&lt;/p&gt;
&lt;p&gt;The metairq sample uses a resetting z_add_timeout()&amp;nbsp;for the timer. Is this ok to use system timer&amp;nbsp;or do we need to &amp;nbsp;look at a different timer module that can be&amp;nbsp;setup to run in background?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/410180?ContentTypeID=1</link><pubDate>Wed, 15 Feb 2023 20:11:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:301bf2ca-9f28-4b36-9e5a-d95995b57871</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You might also be interrested in the&amp;nbsp;zephyr\samples\kernel\metairq_dispatch sample, as it can give you valueable insight into the latencies of your sample processing under various system loads.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Continuous Background I2C process</title><link>https://devzone.nordicsemi.com/thread/410174?ContentTypeID=1</link><pubDate>Wed, 15 Feb 2023 19:54:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4cb145b9-3f0c-4011-8e31-efbfec95547e</guid><dc:creator>haakonsh</dc:creator><description>[quote user=""]My question is should we submit work to the system workqueue at a rate of 100/second or is there a better way to do this? Would it be less intrusive to the&amp;nbsp;other parts of the application to create a dedicated workqueue (and thus its own thread) for this process alone? Or would a simple timer trigger be best to avoid the hardware effort of supporting another queue?[/quote]
&lt;p&gt;I depends a bit on your latency requirements for the I2C sensor data, and whether you need to process the sensor samples at the same thread priority as the system workqueue or if you need a higher/lower priority.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Can you process samples in batches or do you need every sample to be processed before the next sample is ready?&amp;nbsp;&lt;br /&gt;If so how long can you wait?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;Do you need a driver for the I2C communication or can a basic&amp;nbsp;&lt;a title="Master repeated start sequence" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/twim.html?cp=5_0_0_5_30_3#concept_ebf_cwp_xr"&gt;Master repeated start sequence&lt;/a&gt;&amp;nbsp;get the sensor info? &lt;br /&gt;If so, using a TIMER to trigger a TWIM transfer instead of an RTOS timer will probably reduce the scheduling overhead a fair bit, as well as remove lots of time-scale jitter from your data.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>