<?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>Using I2C, NUS, and Two Timer Interrupts - Reading Sensor from both Timer Interrupts</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/6050/using-i2c-nus-and-two-timer-interrupts---reading-sensor-from-both-timer-interrupts</link><description>Custom Board with MCU NordicSemi nRF51822-QFAA 
 
 
 Softdevice S110 7.1 
 
 
 IAR for ARM 7.1 
 
 
 SDK 7.2 using NUS example 
 
 
 Testing with iPhone 5S, 6 and iPad air (iOS 8.1.3) 
 
 
 / Nexus 5 and Galaxy Note 3 (Android 4.4.2). </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 Mar 2015 11:49:10 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/6050/using-i2c-nus-and-two-timer-interrupts---reading-sensor-from-both-timer-interrupts" /><item><title>RE: Using I2C, NUS, and Two Timer Interrupts - Reading Sensor from both Timer Interrupts</title><link>https://devzone.nordicsemi.com/thread/21175?ContentTypeID=1</link><pubDate>Wed, 18 Mar 2015 11:49:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d79b05a5-4609-4aa2-bc52-58431c1ac959</guid><dc:creator>Stefan Birnir Sverrisson</dc:creator><description>&lt;p&gt;Hi Mango922&lt;/p&gt;
&lt;ol start="0"&gt;
&lt;li&gt;
&lt;p&gt;When you use the softdevice together with a timer, you must explicitly set the priority of the TIMER interrupts, i.e.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; NRF_TIMER1-&amp;gt;INTENSET = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;   
 sd_nvic_SetPriority(TIMER1_IRQn, NRF_APP_PRIORITY_LOW);  
 sd_nvic_EnableIRQ(TIMER1_IRQn);

 NRF_TIMER2-&amp;gt;INTENSET = TIMER_INTENSET_COMPARE0_Enabled &amp;lt;&amp;lt; TIMER_INTENSET_COMPARE0_Pos;   
 sd_nvic_SetPriority(TIMER2_IRQn, NRF_APP_PRIORITY_LOW);  
 sd_nvic_EnableIRQ(TIMER2_IRQn);
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;If you want to synchronize the order of events for the two timers, I guess it would be better to use two compare registers of the same timer.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;If you choose both timers with same priority, then they will not preempt each other, meaning that once one of them starts execution, the other one can not interrupt that execution, it will have to wait for the other one to complete. If however TIMER1 has higher priority than TIMER2, then TIMER1 interrupt can preempt exectuion of TIMER2 interrupt handler.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Defining  NRF_APP_PRIORITY_LOW means ARM priority 3, see &lt;a href="https://devzone.nordicsemi.com/question/23542/nrf51822s-original-interrupt-priority/"&gt;this thread&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;NRF_APP_PRIORITY_HIGH means ARM priority 1&lt;/li&gt;
&lt;li&gt;Softdevice callbacks have ARM priority 3.&lt;/li&gt;
&lt;li&gt;SVC calls (calling the softdevice with sd_*) have ARM priority 2&lt;/li&gt;
&lt;li&gt;Internal softdevice operations have ARM priority 0.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;From the above, e.g. the following can be concluded:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any internal softdevice operation (BLE operation) will preempt any application operation.&lt;/li&gt;
&lt;li&gt;Any peripheral interrupt with NRF_APP_PRIORITY_LOW or NRF_APP_PRIORITY_HIGH will block softdevice callbacks.&lt;/li&gt;
&lt;li&gt;Any peripheral with priority set to NRF_APP_PRIORITY_HIGH will preempt any execution of peripheral with priority NRF_APP_PRIORITY_LOW&lt;/li&gt;
&lt;li&gt;Interrupt handler of peripheral with priority NRF_APP_PRIORITY_LOW can call a SVC softdevice function (starting with sd_*), but interrupt handler of peripheral with priority NRF_APP_PRIORITY_HIGH can not.&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>