ā2022-04-06 04:43 AM
this is my code
uint32_t delayCnt;
int main()
{
ledInit();
SysTick_Config(SystemCoreClock/48000);
while(1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
delay_ms(10000);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
}
}
Solved! Go to Solution.
ā2022-04-06 08:06 AM
Primary enter code here as code
volatile uint32_t delayCnt;
secondary as WJ write your whila is ugly need two delays
int main()
{
ledInit();
SysTick_Config(SystemCoreClock/1000); //for ms systick
while(1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
delay_ms(10000);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
delay_ms(10000);
}
}
ā2022-04-06 05:57 AM
It is much simpler. Just add this line:
#define delay_ms HAL_Delay
That's all. CubeIDE will create the systick handler and initialize systick for you.
ā2022-04-06 06:41 AM
Yeah,that ^^^ . But if you want to use your code you need "volatile" on your delayCnt declaration. Otherwise the compiler may/will optimize out your while() loop in delay_ms() because without "volatile" the compiler thinks the value never changes.
ā2022-04-06 06:42 AM
I am not using CubeIDE I am working in atollic TrueSTUDIO
ā2022-04-06 07:15 AM
> while(1)
> {
> GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
> delay_ms(10000);
> GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
> }
This results in 10s of PC13 (LED?) being ON, and then something like a microsecond of it being OFF.
How do you observe this?
JW
ā2022-04-06 08:06 AM
Primary enter code here as code
volatile uint32_t delayCnt;
secondary as WJ write your whila is ugly need two delays
int main()
{
ledInit();
SysTick_Config(SystemCoreClock/1000); //for ms systick
while(1)
{
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_SET);
delay_ms(10000);
GPIO_WriteBit(GPIOC, GPIO_Pin_13, Bit_RESET);
delay_ms(10000);
}
}
ā2022-04-07 12:09 AM
Thankyou it was really helpful ,I forgot to set other delay after turning off the led it was a silly mistake of mine:grinning_face_with_sweat: .
ā2022-04-07 12:10 AM
I forgot to set other delay after turning off the led it was a silly mistake of mine:grinning_face_with_sweat: .