Hi, I have a problem. I want to create a 1 second delay. My IDE is KEIL, my board is STM32F407. My HSE_VALUE is 8000000 and my PLL_M is 8. But my led is constantly on.
#include "stm32f4xx.h" // Device header
void delay(uint32_t );
void delay(uint32_t time){ while(time--);}
int main(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); while(1) { GPIO_SetBits(GPIOD, GPIO_Pin_13); delay(21000000); GPIO_ResetBits(GPIOD, GPIO_Pin_13); delay(21000000); } }
u2u2 said:void delay(uint32_t time){ while(time--);}
Probably, this is being optimised away.
Try making the counter volatile.
Thanks a lot, worked