<?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>Kinetis Microcontrollers中的主题 Re: I2C function failed when called from ISR</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429163#M24792</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;Which procesor and which board?&lt;/P&gt;&lt;P&gt;Do you have a binary that can be run on a standard board to check the reason?&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, 04 Jun 2015 20:07:14 GMT</pubDate>
    <dc:creator>mjbcswitzerland</dc:creator>
    <dc:date>2015-06-04T20:07:14Z</dc:date>
    <item>
      <title>I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429162#M24791</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a problem calling an I2C function from an ISR. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following code executed with simple_LED_toggle() running OK.&lt;/P&gt;&lt;P&gt;However, when I2C_write_function() is executed, it ran into an infinite loop to check I2C bus busy.&lt;/P&gt;&lt;P&gt;This same I2C_write_function() works 100% OK when it is placed in main() loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, problem is there only when I2C_write_function() is placed in PORTD_IRQHandller()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any hint on this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;void I2C_write_function();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PORTD_IRQHandler()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; PORT_HAL_ClearPinIntFlag(portBaseAddr, pin);&lt;/P&gt;&lt;P&gt;&amp;nbsp; simple_LED_toggle();&lt;/P&gt;&lt;P&gt;&amp;nbsp; I2C_write_function();&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 15:39:20 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429162#M24791</guid>
      <dc:creator>kwjohn</dc:creator>
      <dc:date>2015-06-04T15:39:20Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429163#M24792</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;Which procesor and which board?&lt;/P&gt;&lt;P&gt;Do you have a binary that can be run on a standard board to check the reason?&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, 04 Jun 2015 20:07:14 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429163#M24792</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2015-06-04T20:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429164#M24793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;KW John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't give much details about your platform so this is a guess. Most surely in the BSP your I2C driver is implemented using interrupts, in which case the driver interrupt handling functions will never be called unless they run under a higher interrupt priority. The LED toggle functions can operate under interrupt context as they are simply I/O port write calls that run to completion without firing or requiring interrupts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case of desperate need of writing to this I2C device from the interrupt context, configure its driver in polling mode so it does not generate or use interrupts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a standard rule we should avoid making blocking accesses to slow devices from interrupt handlers. If you are using MQX, you could design your application using semaphores and flags which you signal/set inside the interrupt handling function and handle in a separate task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards, Victor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 20:14:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429164#M24793</guid>
      <dc:creator>VictorLorenzo</dc:creator>
      <dc:date>2015-06-04T20:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429165#M24794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Victor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. More on this problem. The platform is FRDM-K64F. It is a touch sensor interface with PTE24(SCL), PTE25(SDA), reset to sensor (PTB23), IRQ (PTD1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PTD1 configured as a GPIO with code here:&lt;/P&gt;&lt;P&gt;//IRQ interface as a GPIO with interrupt enabled&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;const gpio_input_pin_user_config_t irqPin =&lt;/P&gt;&lt;P&gt; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; .pinName = GPIO_MAKE_PIN(HW_GPIOD, 1),&lt;/P&gt;&lt;P&gt;&amp;nbsp; .config.isPullEnable = true,&lt;/P&gt;&lt;P&gt;&amp;nbsp; .config.pullSelect = kPortPullUp,&lt;/P&gt;&lt;P&gt;&amp;nbsp; .config.isPassiveFilterEnabled = false,&lt;/P&gt;&lt;P&gt;&amp;nbsp; .config.interrupt = kPortIntFallingEdge, &lt;/P&gt;&lt;P&gt; };&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The interrupt function is like:&lt;/P&gt;&lt;P&gt;void PORTD_IRQHandler(void)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PORT_HAL_ClearPinIntFlag(PORTD_BASE, 1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; debug_func();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HAL_I2CWriteRegister(reg, val);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I2C is implemented with CMSIS with definition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* I2C Driver */&lt;/P&gt;&lt;P&gt;#define _I2C_Driver_(n)&amp;nbsp; Driver_I2C##n&lt;/P&gt;&lt;P&gt;#define&amp;nbsp; I2C_Driver_(n) _I2C_Driver_(n)&lt;/P&gt;&lt;P&gt;extern ARM_DRIVER_I2C&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_Driver_(0);&lt;/P&gt;&lt;P&gt;#define&amp;nbsp; ptrI2C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&amp;amp;I2C_Driver_(0))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No I2C interrupt enabled, I think. Instead, this touch sensor will assert the IRQ pin from high to low whenever a finger is detected. That is why kPortIntFallingEdge is there in const gpio_input_pin_user_config_t irqPin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HAL_I2CWriteRegister(uint8_t reg, uint16_t val) is declared like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static bool HAL_I2CWriteRegister(uint8_t reg, uint16_t val)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt; uint8_t data[3] = {reg, (uint8_t)(val&amp;gt;&amp;gt;8), (uint8_t)val};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; ptrI2C-&amp;gt;MasterTransmit(0x48, data, 3, false);&lt;/P&gt;&lt;P&gt; while (ptr2C-&amp;gt;GetStatus().busy);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; if(ptrI2C-&amp;gt;GetDataCount() !=3) &lt;/P&gt;&lt;P&gt; {&lt;/P&gt;&lt;P&gt;&amp;nbsp; return -1;&lt;/P&gt;&lt;P&gt; }&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This same I2C write function works 100% OK in the main loop. It also works in a thread when Bare Metal Abstraction Layer is used, but not in the ISR. It always hang up at the infinite while loop while (ptr2C-&amp;gt;GetStatus().busy) in ISR. As a debug action I placed another led toggle function debug_func() in the same ISR which works OK.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This puzzles me a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree that semaphore can be used but, why the I2C function doesn't work in ISR? I have implemented the same code in Texas Instruments Tiva C and it works OK, even though there is a blocking function in ISR like the I2C...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 02:29:41 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429165#M24794</guid>
      <dc:creator>kwjohn</dc:creator>
      <dc:date>2015-06-05T02:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429166#M24795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The platform is FRDM-K64F. It is a touch sensor interface with PTE24(SCL), PTE25(SDA), reset to sensor (PTB23), IRQ (PTD1). Some more details in another reply to Victor below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 02:30:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429166#M24795</guid>
      <dc:creator>kwjohn</dc:creator>
      <dc:date>2015-06-05T02:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429167#M24796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello John&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is not clear how ptrI2C-&amp;gt;MasterTransmit() and ptr2C-&amp;gt;GetStatus() operate.&lt;/P&gt;&lt;P&gt;Since the I2C HW is different on the Tiva and the Kinetis the content will not be the same and may also have different implementations/configurations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the bus really busy (when you look at the signals with an oscilloscope)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens when you debug the code?&amp;nbsp; it should be visible what is being read and why it behaves differently when called from main or when called from the ISR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You don't seem to be sure whether ptrI2C-&amp;gt;MasterTransmit() is using interrupts or not. If it is, it could well fail if the port IRQ's priority is higher than the I2C's interrupt priority - why not set the prorities to ensure no potential problem? Or show the code so that it is visible whether it is interrupt driven or not?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or attach the binary that fails so that it can be run on the FRDM-K64F to check what is is doing in its failing wait loop.&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;&lt;/P&gt;&lt;P&gt;Kinetis: &lt;A href="http://www.utasker.com/kinetis.html" title="http://www.utasker.com/kinetis.html"&gt;µTasker Kinetis support&lt;/A&gt; &lt;/P&gt;&lt;P&gt;K64: &lt;A href="http://www.utasker.com/kinetis/FRDM-K64F.html" title="http://www.utasker.com/kinetis/FRDM-K64F.html"&gt;µTasker Kinetis FRDM-K64F support&lt;/A&gt;&amp;nbsp; / &lt;A href="http://www.utasker.com/kinetis/TWR-K64F120M.html" title="http://www.utasker.com/kinetis/TWR-K64F120M.html"&gt;µTasker Kinetis TWR-K64F120M support&lt;/A&gt;&amp;nbsp; / &lt;A href="http://www.utasker.com/kinetis/TWR-K65F180M.html" title="http://www.utasker.com/kinetis/TWR-K65F180M.html"&gt;µTasker Kinetis TWR-K65F180M support&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the complete "out-of-the-box" Kinetis experience and faster time to market &lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 11:11:54 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429167#M24796</guid>
      <dc:creator>mjbcswitzerland</dc:creator>
      <dc:date>2015-06-05T11:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429168#M24797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot. You are right. I2C ISR has been enabled with one of the CMSIS style statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I2Cdrv-&amp;gt;&lt;A class="code" href="https://community.nxp.com/" title="Pointer to ARM_I2C_PowerControl : Control I2C Interface Power."&gt;PowerControl&lt;/A&gt; (&lt;A class="code" href="https://community.nxp.com/" title="Power on: full operation at maximum performance."&gt;ARM_POWER_FULL&lt;/A&gt;);&lt;/P&gt;&lt;P&gt;with I2C_PowerControl() run like this: (extracted from I2C_MK64F.c released by Freescale Pack for Keil MDK CMSIS)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;static int32_t I2C_PowerControl (ARM_POWER_STATE state, I2C_RESOURCES *i2c) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; if ((i2c-&amp;gt;ctrl-&amp;gt;flags &amp;amp; I2C_INIT) == 0U) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Driver not initialized */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return (ARM_DRIVER_ERROR);&lt;BR /&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; switch (state) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; case ARM_POWER_OFF:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i2c-&amp;gt;ctrl-&amp;gt;status.busy) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Transfer in progress */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ARM_DRIVER_ERROR_BUSY;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i2c-&amp;gt;ctrl-&amp;gt;flags &amp;amp; I2C_POWER) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c-&amp;gt;ctrl-&amp;gt;flags &amp;amp;= ~(I2C_POWER | I2C_SETUP);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Disable I2C interrupt requests in NVIC */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NVIC_DisableIRQ (i2c-&amp;gt;irq_num);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Disable I2C peripheral */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_HAL_Disable (i2c-&amp;gt;base);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Disable I2C peripheral clock */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM_HAL_DisableClock (SIM_BASE, i2c-&amp;gt;clock_gate);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; case ARM_POWER_LOW:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return ARM_DRIVER_ERROR_UNSUPPORTED;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; case ARM_POWER_FULL:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ((i2c-&amp;gt;ctrl-&amp;gt;flags &amp;amp; I2C_POWER) == 0U) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable I2C peripheral clock */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SIM_HAL_EnableClock (SIM_BASE, i2c-&amp;gt;clock_gate);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable I2C interrupt requests in NVIC */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NVIC_EnableIRQ (i2c-&amp;gt;irq_num);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Initialize peripheral to known state */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_HAL_Init (i2c-&amp;gt;base);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable START/STOP condition detection interrupt */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_HAL_SetStartStopIntCmd (i2c-&amp;gt;base, true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable I2C interrupts */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_HAL_SetIntCmd (i2c-&amp;gt;base, true);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Enable I2C peripheral */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I2C_HAL_Enable (i2c-&amp;gt;base);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Ready for operation */&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i2c-&amp;gt;ctrl-&amp;gt;flags |= I2C_POWER;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break;&lt;BR /&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; return ARM_DRIVER_OK;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A good lesson here: don't blindly follow those examples from documents/app notes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Jun 2015 18:13:35 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429168#M24797</guid>
      <dc:creator>kwjohn</dc:creator>
      <dc:date>2015-06-05T18:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429169#M24798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The function does not work in the ISR because the low level driver implements transactions using interrupts, the write function configures the hardware IP and the driver code and simply waits for transaction conclusion, that is the loop checking the busy state flag.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should put the I2C access code out of the ISR, it should not run under interrupt context.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a bad design idea, but you could configure the I2C driver for generating interrupts with a higher priority and make sure higher priority interrupts are not disabled in your ISR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Victor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Jun 2015 15:21:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429169#M24798</guid>
      <dc:creator>VictorLorenzo</dc:creator>
      <dc:date>2015-06-06T15:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: I2C function failed when called from ISR</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429170#M24799</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Victor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of using I2C in ISR, I have followed your recommendation to use RTOS with a semaphore. Posting semaphore from ISR with pending semaphore calling I2C is more elegant.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This problem has been solved. Thanks a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2015 01:24:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/I2C-function-failed-when-called-from-ISR/m-p/429170#M24799</guid>
      <dc:creator>kwjohn</dc:creator>
      <dc:date>2015-06-12T01:24:03Z</dc:date>
    </item>
  </channel>
</rss>

