cancel
Showing results for 
Search instead for 
Did you mean: 

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

ag n.1
Associate II

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);

}

}

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II

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);
 }
}

View solution in original post

7 REPLIES 7
Pavel A.
Evangelist III

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.

Bob S
Principal

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.

I am not using CubeIDE I am working in atollic TrueSTUDIO

> 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

MM..1
Chief II

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);
 }
}

Thankyou it was really helpful ,I forgot to set other delay after turning off the led it was a silly mistake of mine😅 .

I forgot to set other delay after turning off the led it was a silly mistake of mine😅 .