<?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 Delay loops gone crazy in Kinetis Microcontrollers</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2255470#M68072</link>
    <description>&lt;P&gt;I'm picking up a project that I put aside 7 months ago.&amp;nbsp; It involves using SPI to communicate with a Nordic Semiconductor nRF24l01 module from a FRDM-K64F using MCUExpresso24.12(Build148) IDE.&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;When I left it, it happily wrote sign-on and copyright banners and then went to handling RF.&lt;/P&gt;&lt;P&gt;While it still sends RF, it is painfully slow sending two screens of data to the HD44870 2x16 display.&amp;nbsp; &amp;nbsp;Like 3 seconds per character.&lt;/P&gt;&lt;P&gt;As I am using an LCD daughter card designed for the Arduino, it does not have the&amp;nbsp; BUSY bit wired from the LCD, so I am using delay loops.&lt;/P&gt;&lt;P&gt;But nothing should have been changed in the program, sitting on the shelf!&amp;nbsp; As of the last time I ran it, the screen update was like a flash, as is evidenced by one FRDM-K64F that still had the old version of the program in it.&lt;/P&gt;&lt;P&gt;I have tried stepping through all delay loops, they have the expected number of cycles.&amp;nbsp; I have tried trapping unwanted interrupts, even turning of interrupts, no change.&amp;nbsp; I suspected maybe an update to gcc has an optimisation flag set/no set, but that would have the opposite effect, speeding up the display and getting garbage due to not waiting long enough.&amp;nbsp; The last working version was compiled with the same version of MCUExpresso.&amp;nbsp; I am not aware of any updates.&lt;/P&gt;&lt;P&gt;It stays slow whether it is connected to the PC's IDE connection using Linkserver or standalone!&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The LCD is not going to be in the final product, it's just for debugging, but this strange anomaly is driving me crazy and I need to get it fixed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any help really appreciated, I'm hoping somebody has seen something like this and has an answer!&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Nigel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Dec 2025 17:40:00 GMT</pubDate>
    <dc:creator>ve3id</dc:creator>
    <dc:date>2025-12-04T17:40:00Z</dc:date>
    <item>
      <title>Delay loops gone crazy</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2255470#M68072</link>
      <description>&lt;P&gt;I'm picking up a project that I put aside 7 months ago.&amp;nbsp; It involves using SPI to communicate with a Nordic Semiconductor nRF24l01 module from a FRDM-K64F using MCUExpresso24.12(Build148) IDE.&lt;/P&gt;&lt;P&gt;.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;When I left it, it happily wrote sign-on and copyright banners and then went to handling RF.&lt;/P&gt;&lt;P&gt;While it still sends RF, it is painfully slow sending two screens of data to the HD44870 2x16 display.&amp;nbsp; &amp;nbsp;Like 3 seconds per character.&lt;/P&gt;&lt;P&gt;As I am using an LCD daughter card designed for the Arduino, it does not have the&amp;nbsp; BUSY bit wired from the LCD, so I am using delay loops.&lt;/P&gt;&lt;P&gt;But nothing should have been changed in the program, sitting on the shelf!&amp;nbsp; As of the last time I ran it, the screen update was like a flash, as is evidenced by one FRDM-K64F that still had the old version of the program in it.&lt;/P&gt;&lt;P&gt;I have tried stepping through all delay loops, they have the expected number of cycles.&amp;nbsp; I have tried trapping unwanted interrupts, even turning of interrupts, no change.&amp;nbsp; I suspected maybe an update to gcc has an optimisation flag set/no set, but that would have the opposite effect, speeding up the display and getting garbage due to not waiting long enough.&amp;nbsp; The last working version was compiled with the same version of MCUExpresso.&amp;nbsp; I am not aware of any updates.&lt;/P&gt;&lt;P&gt;It stays slow whether it is connected to the PC's IDE connection using Linkserver or standalone!&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The LCD is not going to be in the final product, it's just for debugging, but this strange anomaly is driving me crazy and I need to get it fixed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any help really appreciated, I'm hoping somebody has seen something like this and has an answer!&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Nigel&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Dec 2025 17:40:00 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2255470#M68072</guid>
      <dc:creator>ve3id</dc:creator>
      <dc:date>2025-12-04T17:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Delay loops gone crazy</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2256173#M68074</link>
      <description>GCC when set to build the 'Small' model with -Os can be aggressive about removing code, breaking busy loops that have no side effects.&amp;nbsp; I always put nop() that has the proper guards into my loops. Odd delay behavior in this case indicates a missing volatile somewhere.&lt;BR /&gt;&lt;BR /&gt;Early AVR-LIBC implementations requires passing a float to the delay functions. Compiler coercions turned it into the required number of cycles. Failing to do that got strange delays. Modern implementations take an unsigned int.&lt;BR /&gt;&lt;BR /&gt;That you can single step does seem to negate those.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;static inline void nop( void )&lt;BR /&gt;{&lt;BR /&gt;__asm__ __volatile__ ("nop");&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Dec 2025 14:01:39 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2256173#M68074</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2025-12-05T14:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Delay loops gone crazy</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2256282#M68075</link>
      <description>Thanks, Bob,&lt;BR /&gt;I did find one missing volatile in another loop that had previously raised my eyebrows but not important enough to tackle until I had fixed the main problem, however I still have the same problem. But now I am seeing stray interrupts, so that is where I will spend the next little while &lt;LI-EMOJI id="lia_slightly-smiling-face" title=":slightly_smiling_face:"&gt;&lt;/LI-EMOJI&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 05 Dec 2025 18:23:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/Delay-loops-gone-crazy/m-p/2256282#M68075</guid>
      <dc:creator>ve3id</dc:creator>
      <dc:date>2025-12-05T18:23:16Z</dc:date>
    </item>
  </channel>
</rss>

