DELAYS DON`T WORK AS EXPECTED
I would like to make a led connected to pin 6 flash, using this code:
while(1)
{
GPIO_WriteBit(GPIOA, GPIO_Pin_6, Bit_RESET);
delay();
GPIO_WriteBit(GPIOA, GPIO_Pin_6, Bit_SET);
delay();
}
To generate the required delay for blinking, I wrote the following function:
void delay(void)
{
uint32_t delay = 0;
while(delay < 5000000)
{
++delay;
}
}
This should generate enough delay for me to see the LED flash. The problem is that it didn’t matter what value I wrote in the delay variable, the led just didn’t blink. It was as if the compiler did not execute the delay function.
So I decided to create a new project within SW4STM32 and simply copied and pasted the code into the new project. Then the LED finally started to flash.
Does anyone have any idea why this could be happening?