AnsweredAssumed Answered

Delay function with MCUXpresso and frdm-k64f does not work

Question asked by Leandro Fabián Rocco on Mar 17, 2019
Latest reply on Mar 19, 2019 by Leandro Fabián Rocco

Hi,

 

I am using MCUXpresso IDE v10.2.1 [Build 795] to program a FRDM-K64F board.

 

I need a delay function to generate a delay of milliseconds and microseconds, for this I am writing the following codes:

 

#define SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_CoreSysClk)

void delay_us(uint32_t value)
{
    uint32_t d = SOURCE_CLOCK / 1000000 * value;
    uint32_t i;
    for (i = 0U; i < d; ++i)
    {
        __asm("NOP");
    }
}

void delay_ms(uint32_t value)
{
    uint32_t d = SOURCE_CLOCK / 1000 * value;
    uint32_t i;
    for (i = 0U; i < d; ++i)
    {
        __asm("NOP");
    }
}

 

I am testing the functions to blink an LED. The problem is that no matter the configured SystemClock frequency, delay functions always blink the LED at a frequency around 10 times lower than the SystemClock, in other words, if I call the functions as follows:

 

delay_ms(1000); // Spected delay of 1 second

 

the delay I get is about 10 seconds.

 

What is the problem?

 

Regards.

 

Clocks configurations

Outcomes