<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Having trouble setting NVIC interrupt priority on KL05 in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699156#M42991</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The NVIC is part of the Cortex core and so is not documented in the Kinetis user's manuals - you can get all core documentation from ARM: &lt;A href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0432c/Cihbecee.html" target="test_blank"&gt;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0432c/Cihbecee.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are just starting out with Kinetis try the uTasker open source version on Git Hub since it allows you to simulate operation and will cut your learning curve and development times dramatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Furthermore it is the only solution that allows you to develop on one Kinetis part but permits the code to run on almost any other Kinetis part (including i.MX RTs if the project finds it needs more speed) without a redesign being necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;BR /&gt;&lt;EM&gt;[uTasker project developer for Kinetis and i.MX RT]&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Apr 2020 16:18:21 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2020-04-02T16:18:21Z</dc:date>
    <item>
      <title>Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699151#M42986</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using a KL05Z32 and I cannot seem to set NVIC priority for two interrupts.&amp;nbsp; I am trying the same method for the PIT and the I2C interrupt.&amp;nbsp; When I run the code with a debugger and I directly inspect the NVIC priority, I do not see a change after using the 'set_irq_priority()' function or directly writing to the NVIC_IPR5 register.&amp;nbsp; Here is a code sample for setting the PIT priority:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;void PIT_Init(void)
{
 // Enable PIT clock
 SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // enable PIT module
 
 /* Enable PIT Interrupt in NVIC*/ 
 enable_irq(INT_PIT - 16);
 
 /* Set PIT priority relatively low so as not to interfere with communication interrupts */
 set_irq_priority(INT_PIT - 16, 1);
 //NVIC_IPR5 = 0x01;
 
 PIT_MCR = 0x00; // MDIS = 0 enables timer
 PIT_TCTRL1 = 0x00; // disable PIT0
 // Configure PIT to produce an interrupt every 1ms
 PIT_LDVAL1 = 23999; // 24000 - 1 cycles at 24MHz
 PIT_TCTRL1 = PIT_TCTRL_TIE_MASK; // enable PIT0 and interrupt
 PIT_TFLG1 = 0x01; // clear flag
 PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK;
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Oct 2017 22:53:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699151#M42986</guid>
      <dc:creator>jeffmajeff</dc:creator>
      <dc:date>2017-10-04T22:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699152#M42987</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Jeff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may be using code from a Cortex-m4 based part rather than a Cortex-M0+ part.&lt;/P&gt;&lt;P&gt;Cortex-m4 (eg. K60 ) has 16 priority levels but the Cortex-M0+ (eg. KL05) has 4.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you set it manually you are writing the value incorrectly to the register because it is left aligned and not right aligned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This code will do it correctly:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;unsigned char ucPriority&amp;nbsp; = 1; // (or whatever) 0..3 for KL05&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;NVIC_IPR5 = = (ucPriority &amp;lt;&amp;lt; __NVIC_PRIORITY_SHIFT); // define the interrupt's priority (16 levels for K and 4 levels for KE/KL)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;#define __NVIC_PRIORITY_SHIFT&amp;nbsp;&amp;nbsp; 6&lt;/SPAN&gt;&lt;BR /&gt;is to be used for Cortex-M0+ based parts&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;#define __NVIC_PRIORITY_SHIFT&amp;nbsp;&amp;nbsp; 4&lt;/SPAN&gt;&lt;BR /&gt;for Cortex-M4 parts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;In the uTasker project the PIT and I2C interrupts (priority and handlers) are set up with:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;&lt;EM&gt;fnEnterInterrupt(irq_PIT_ID, PRIORITY_PIT, _PIT_Interrupt);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;&lt;EM&gt;fnEnterInterrupt(irq_I2C0_ID, PRIORITY_I2C0, _I2C_Interrupt_0);&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Which requires no porting and is fool-proof. If anything is wrong or out of range its simulator will report it as a fatal error.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Slash your project time with uTasker and KL05 simulation at&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis.html&lt;/A&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="https://community.nxp.com/external-link.jspa?url=http%3A%2F%2Fwww.utasker.com%2Fkinetis%2FFRDM-KL05Z.html" rel="nofollow" target="_blank"&gt;http://www.utasker.com/kinetis/FRDM-KL05Z.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Also free and open source....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Oct 2017 23:59:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699152#M42987</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-10-04T23:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699153#M42988</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see what you mean.&lt;/P&gt;&lt;P&gt;Would it be something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;NVIC_IPR5 = &lt;SPAN&gt;(ucPriority &amp;lt;&amp;lt; (__NVIC_PRIORITY_SHIFT + 16))&lt;BR /&gt;&lt;BR /&gt;since (INT_PIT - 16) % 4 = 2 we have have to set the priority for IRQ2 on NVIC_IPR5, or am I interpreting that wrong?&amp;nbsp; Otherwise you wouldn't be able to set the priority independently for each of the interrupts that share NVIC_IPR5.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 00:52:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699153#M42988</guid>
      <dc:creator>jeffmajeff</dc:creator>
      <dc:date>2017-10-05T00:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699154#M42989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Jeff&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see, your code base is doing long word accesses which is making it over-complicated.&lt;/P&gt;&lt;P&gt;This is the simplest way - just write each priority as a byte and then there is no complication.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;volatile unsigned char *ptrPriority = IRQ0_3_PRIORITY_REGISTER_ADD; // set a pointer to the first priority register location&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;ptrPriority += iInterruptID; // move to the priority location used by this interrupt&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;*ptrPriority = (ucPriority &amp;lt;&amp;lt; __NVIC_PRIORITY_SHIFT);&amp;nbsp; // define the interrupt's priority (16 levels for K and 4 levels for KE/KL)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Otherwise the PIT one for KL05 does happen to be a 16 bit shift (but you need to calculate the shift for each ID and it will change depending on which processor you are on - non-portable and costs time, money and new testing/debugging in case you were to need to re-use code on a different part.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;KL05 PIT interrupt ID is 0x16 (22), so it needs to be set in the IRQ20_23_PRIORITY_REGISTER priority register (this is the 6th register in this area and therefore your framework presumably calls it &lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;NVIC_IPR5&lt;/SPAN&gt;.&lt;/P&gt;&lt;P&gt;The actual bit involved to set a priority of 1 is 0x00400000, so your formula is correct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You do still have an error though because &lt;BR /&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;NVIC_IPR5 = &lt;SPAN&gt;(ucPriority &amp;lt;&amp;lt; (__NVIC_PRIORITY_SHIFT + 16));&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;writes the other three neighbor vector priorities to 0 (if they were previously set), so the correct code when doing this particular interrupt's long word access would be:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;NVIC_IPR5 = (NVIC_IPR5 &amp;amp; 0xff00ffff) | &lt;SPAN&gt;(ucPriority &amp;lt;&amp;lt; (__NVIC_PRIORITY_SHIFT + 16)));&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Therefore I prefer the simple byte access method (above) because it only requires the ID of the interrupt to be known and no calculating on the back of a napkin is needed each time one is used (with the associated risk of errors).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, the user's manual gives the description for each priority register, showing the locations (and shifts) involved.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_2.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/12962i3FBA487F0065E314/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_2.png" alt="pastedImage_2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Finally, you may find code doing this (eg. Cortex CMSIS code)&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;int iPriorities = 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;unsigned long ullPriority;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;IRQ0_3_PRIORITY_REGISTER = 0xff0000; // set lowest priority (hoping 256 are available)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;ulPriority = IRQ0_3_PRIORITY_REGISTER; // read back the register to see how many bits stuck&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;while ((ulPriority &amp;amp; 0x80000000) != 0) { // if the priority bit is implemented&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; iPriorities *= 2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ulPriority&amp;nbsp; &amp;lt;&amp;lt;= 1;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier,monospace;"&gt;//iPriorities now is equal to the priority levels that this processor type supports...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 02:37:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699154#M42989</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2017-10-05T02:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699155#M42990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where do I find IPR registers addresses in the MKL28Z manual? I can't find it anywhere...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2020 14:12:10 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699155#M42990</guid>
      <dc:creator>ribeiroruan2</dc:creator>
      <dc:date>2020-04-02T14:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699156#M42991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The NVIC is part of the Cortex core and so is not documented in the Kinetis user's manuals - you can get all core documentation from ARM: &lt;A href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0432c/Cihbecee.html" target="test_blank"&gt;http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0432c/Cihbecee.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are just starting out with Kinetis try the uTasker open source version on Git Hub since it allows you to simulate operation and will cut your learning curve and development times dramatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Furthermore it is the only solution that allows you to develop on one Kinetis part but permits the code to run on almost any other Kinetis part (including i.MX RTs if the project finds it needs more speed) without a redesign being necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;BR /&gt;&lt;EM&gt;[uTasker project developer for Kinetis and i.MX RT]&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:18:21 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699156#M42991</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2020-04-02T16:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Having trouble setting NVIC interrupt priority on KL05</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699157#M42992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Apr 2020 16:35:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Having-trouble-setting-NVIC-interrupt-priority-on-KL05/m-p/699157#M42992</guid>
      <dc:creator>ribeiroruan2</dc:creator>
      <dc:date>2020-04-02T16:35:22Z</dc:date>
    </item>
  </channel>
</rss>

