<?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 Issue with using Triger MUX with ADC ISR in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-using-Triger-MUX-with-ADC-ISR/m-p/1370756#M182986</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the i.MX7ULP evaluation board, IAR Embedded Workbench Arm 8.50.1, and J-Link Plus for a project. And I encountered several issues where the ACD interrupt is not called.&lt;/P&gt;&lt;P&gt;I used example trgmux_lptmr_trigger_lpit under .\boards\evkmcimx7ulp\driver_examples\trgmux\lptmr_trigger_lpit in NXP’s official SDK_2.9.0_EVK-MCIMX7ULP as a starting point for my project (will be referred to as “Example 1” below). I also added some code from lpadc_single_interrupt under .\boards\evkmcimx7ulp\driver_examples\lpadc\single_interrupt in the same SDK (will be referred to as “Example 2” below). I needed both functionalities of timer trigger and ADC interrupt.&lt;/P&gt;&lt;P&gt;Specifically:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I moved the initialization portion of the code in Example 2's main() to a new function called AdcInit(). I then added a call to this function from DEMO_InitLptmrTrigger() which is called by main() in Example 1.&lt;/LI&gt;&lt;LI&gt;I made the following changes to DEMO_InitLptmrTrigger() from Example 1:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;mLpadcConfigStruct.FIFOWatermark = 15U; /* Set watermark as 15U. */
LPTMR_SetTimerPeriod(LPTMR0, 1600U);​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first statement above is to get 16 samples before the ADC triggers an ISR. The second statement above is to set the sampling period to 100 microseconds (16 MHz / (1 s / 100 us)).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I added ADC1_IRQHandler()/DEMO_LPADC_IRQ_HANDLER_FUNC() from Example 2 to Example 1&lt;/LI&gt;&lt;LI&gt;I added my own code to ADC1_IRQHandler() that reads all 16 values from ADC buffer when ADC1_IRQHandler() is called (which means the ADC buffer is full with 16 values):&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    g_LpadcConversionInProgressFlag = true;
    int i = 0;
    while (g_LpadcConversionInProgressFlag)
    {
        g_LpadcConversionInProgressFlag = LPADC_GetConvResult(DEMO_LPADC_BASE, &amp;amp;g_LpadcResultConfigStruct);
        local_data[i] = ((g_LpadcResultConfigStruct.convValue) &amp;gt;&amp;gt; 3U);
        i++;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I added my own code to ADC1_IRQHandler() that toggles a GPIO pin whenever ADC1_IRQHandler() is called:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    /* Toggle GPIO to PIN J11-1*/
    GPIO_PortToggle(BOARD_LED_GPIO, 1u &amp;lt;&amp;lt; BOARD_LED_GPIO_PIN);
    SDK_ISR_EXIT_BARRIER;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I removed function LPIT0_IRQHandler() in Example 1.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The resulting code is attached.&lt;/P&gt;&lt;P&gt;The only way to have ADC1_IRQHandler() called consistently, as observed through the GPIO toggle, is to reset the board by pressing the physical reset button.&lt;/P&gt;&lt;P&gt;If I stop debugging from IAR, and restart debugging, then ADC1_IRQHandler() is still called.&lt;/P&gt;&lt;P&gt;If I try to load another workspace, and then reload this workspace without resetting the board, then ADC1_IRQHandler() is not called.&lt;/P&gt;&lt;P&gt;If I reset the board and start debugging, ADC1_IRQHandler() is called again.&lt;/P&gt;&lt;P&gt;If I choose Reset in IAR's Debug menu, it will jump back to main(), and when I choose Go in IAR's Debug menu, ADC1_IRQHandler() is not called anymore.&lt;/P&gt;&lt;P&gt;In summary, either of these two things makes ADC1_IRQHandler() stop being called anymore: 1. Load another workspace and reload this workspace. 2. Reset in the debugging process so it jumps back to main() and continue debugging.&lt;/P&gt;&lt;P&gt;Can you help with this issue? Thank you!&lt;/P&gt;</description>
    <pubDate>Fri, 12 Nov 2021 16:16:44 GMT</pubDate>
    <dc:creator>qingg</dc:creator>
    <dc:date>2021-11-12T16:16:44Z</dc:date>
    <item>
      <title>Issue with using Triger MUX with ADC ISR</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-using-Triger-MUX-with-ADC-ISR/m-p/1370756#M182986</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using the i.MX7ULP evaluation board, IAR Embedded Workbench Arm 8.50.1, and J-Link Plus for a project. And I encountered several issues where the ACD interrupt is not called.&lt;/P&gt;&lt;P&gt;I used example trgmux_lptmr_trigger_lpit under .\boards\evkmcimx7ulp\driver_examples\trgmux\lptmr_trigger_lpit in NXP’s official SDK_2.9.0_EVK-MCIMX7ULP as a starting point for my project (will be referred to as “Example 1” below). I also added some code from lpadc_single_interrupt under .\boards\evkmcimx7ulp\driver_examples\lpadc\single_interrupt in the same SDK (will be referred to as “Example 2” below). I needed both functionalities of timer trigger and ADC interrupt.&lt;/P&gt;&lt;P&gt;Specifically:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I moved the initialization portion of the code in Example 2's main() to a new function called AdcInit(). I then added a call to this function from DEMO_InitLptmrTrigger() which is called by main() in Example 1.&lt;/LI&gt;&lt;LI&gt;I made the following changes to DEMO_InitLptmrTrigger() from Example 1:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;mLpadcConfigStruct.FIFOWatermark = 15U; /* Set watermark as 15U. */
LPTMR_SetTimerPeriod(LPTMR0, 1600U);​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The first statement above is to get 16 samples before the ADC triggers an ISR. The second statement above is to set the sampling period to 100 microseconds (16 MHz / (1 s / 100 us)).&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I added ADC1_IRQHandler()/DEMO_LPADC_IRQ_HANDLER_FUNC() from Example 2 to Example 1&lt;/LI&gt;&lt;LI&gt;I added my own code to ADC1_IRQHandler() that reads all 16 values from ADC buffer when ADC1_IRQHandler() is called (which means the ADC buffer is full with 16 values):&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    g_LpadcConversionInProgressFlag = true;
    int i = 0;
    while (g_LpadcConversionInProgressFlag)
    {
        g_LpadcConversionInProgressFlag = LPADC_GetConvResult(DEMO_LPADC_BASE, &amp;amp;g_LpadcResultConfigStruct);
        local_data[i] = ((g_LpadcResultConfigStruct.convValue) &amp;gt;&amp;gt; 3U);
        i++;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I added my own code to ADC1_IRQHandler() that toggles a GPIO pin whenever ADC1_IRQHandler() is called:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    /* Toggle GPIO to PIN J11-1*/
    GPIO_PortToggle(BOARD_LED_GPIO, 1u &amp;lt;&amp;lt; BOARD_LED_GPIO_PIN);
    SDK_ISR_EXIT_BARRIER;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I removed function LPIT0_IRQHandler() in Example 1.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The resulting code is attached.&lt;/P&gt;&lt;P&gt;The only way to have ADC1_IRQHandler() called consistently, as observed through the GPIO toggle, is to reset the board by pressing the physical reset button.&lt;/P&gt;&lt;P&gt;If I stop debugging from IAR, and restart debugging, then ADC1_IRQHandler() is still called.&lt;/P&gt;&lt;P&gt;If I try to load another workspace, and then reload this workspace without resetting the board, then ADC1_IRQHandler() is not called.&lt;/P&gt;&lt;P&gt;If I reset the board and start debugging, ADC1_IRQHandler() is called again.&lt;/P&gt;&lt;P&gt;If I choose Reset in IAR's Debug menu, it will jump back to main(), and when I choose Go in IAR's Debug menu, ADC1_IRQHandler() is not called anymore.&lt;/P&gt;&lt;P&gt;In summary, either of these two things makes ADC1_IRQHandler() stop being called anymore: 1. Load another workspace and reload this workspace. 2. Reset in the debugging process so it jumps back to main() and continue debugging.&lt;/P&gt;&lt;P&gt;Can you help with this issue? Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Nov 2021 16:16:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Issue-with-using-Triger-MUX-with-ADC-ISR/m-p/1370756#M182986</guid>
      <dc:creator>qingg</dc:creator>
      <dc:date>2021-11-12T16:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with using Triger MUX with ADC ISR</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/Issue-with-using-Triger-MUX-with-ADC-ISR/m-p/1382132#M184033</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm Qing's colleague, I looked into the issue, a long story short, if the system is reset when the NVIC's ADC1 interrupt is active(i.e. NVIC_IABR1's ACTIVE59 is set to 1), then the interrupt will never be executed again.&amp;nbsp; The ADC1 active's bit is not cleared if there is a reset in middle of the interrupt(i.e. use the reset processor button in the IDE).&amp;nbsp; Once that active bit is set for an interrupt, according to ARM's v7 documentation:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If an interrupt is active when it is disabled, it remains in the active&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;state until this is cleared by a reset or an exception return.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Therefore as a temporary work around, I added code to detect this issue and do a reset:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if(NVIC_GetActive(DEMO_LPADC_IRQn))
{
  NVIC_SystemReset();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This does fix the issue, the Active bit is cleared and the ADC interrupt is cleared.&amp;nbsp; Is there an alternative way to clear NVIC_IABR1 bit(s) than a system reset?&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;David&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Dec 2021 19:06:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/Issue-with-using-Triger-MUX-with-ADC-ISR/m-p/1382132#M184033</guid>
      <dc:creator>davidguinn</dc:creator>
      <dc:date>2021-12-06T19:06:54Z</dc:date>
    </item>
  </channel>
</rss>

