cancel
Showing results for 
Search instead for 
Did you mean: 

Delay generation in 32F103

KGupt.1
Associate III

want to generate delay using STM32F103 Timer peripheral(TIM2) and coding in bare metal without HAL

From the Youtube videos and google links i found out that

-->Timer Frequency(TF) = System Clock(Fsysclk)/Prescalor(TIM2PSC)

-->Timer time Period(TTP) = 1/timer frequency(TF)

-->Time delay by timer = Timer Time Period(TTP) * Timer auto reload register(TIM2ARR)

this is the basic formula and concept for generating delay using the Timebase unit of the Timer peripheral.

But here the issue is I have written this code: https://pastebin.com/seE3m8r7

configured my SystemClk = 32mhz,

setting Timer Bus APB1 at = 32Mhz only

TIM2PSC = 65535, TIM2ARR = 500

So using the above formula and concept I should get a delay of 1sec when counter register overflow(while(!(TIM2->SR & TIM_SR_UIF));

But that is not happening in the real case, my led is not blinking at all. When I check with the logic analyzer then also it shows this.

I am not getting exactly where I am wrong, whether in the formula part?? or in configuring Timer ??? or My system clock configuration.

I am really stuck on this for the past 2-3 days, not getting any clear idea, will be waiting for valuable and insightful suggestions 0693W000008G7vXQAS.png

1 REPLY 1

Hello

>> TIM2->CR1 |= (TIM_CR1_URS) | (~TIM_CR1_UDIS); // Only counter overflow/underflow generates an update

this ored inverted bit sets all bits of CR1 .