Hi I am working STM32F030 series for delay using SysTick.
I am new to this field and by going through the data sheet I created a delay function,
I don't know where I am going wrong , Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 4: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.
- Labels:
-
STM32F0 Series
-
SysTick
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 8: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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 5: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 6:42 AM
I am not using CubeIDE I am working in atollic TrueSTUDIO
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 7: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-06 8: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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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: .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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: .
