cancel
Showing results for 
Search instead for 
Did you mean: 

Not able in setting TIMx_ARR

Dario Laezza
Associate II
Posted on May 09, 2017 at 17:35

Hi to everyone,

I'm Dario Laezza and I'm approaching the STM32 platform using the Nucleo F401RE. I would make a LED blink using the TIM1 to create a wait function. I'm able to set the Prescaler and other parameters in the CR1 register but I cannot set the ARR value, it's always set to its maximum (65 536). I have read the Reference Manual but I do not find it clear in explaining how to do it. Can anyone help me? Thank you so much.

Dario Laezza

#stm32-tim #stm32-f
7 REPLIES 7
Dario Laezza
Associate II
Posted on May 09, 2017 at 17:48

I forgot to say that I'm using IAR Embedded Workbench.

Christopher Pappas
Senior II
Posted on May 09, 2017 at 17:59

You need to set the ARPE (Auto Reload Preload Enable) register to 'True' on the timer you are using. Then you can change the TIMx_ARR on-the-fly.

https://community.st.com/0D50X00009XkYKaSAN

may be of assistance to you as well.

Posted on May 09, 2017 at 18:48

Thank you pappas for your answer but the I've already tried this way. What I do in my function for setting the Timer is:

unsigned int* REGpointer;

unsigned int ARR=ms;

REGpointer=RCC_APB2ENR;

*REGpointer |= TIM1EN;

REGpointer=TIM1_CR1;

*REGpointer |= ARPE;

REGpointer=TIM1_ARR;

*REGpointer |= ARR;

REGpointer=TIM1_PSC;

*REGpointer |= PSC;

REGpointer=RCC_APB2ENR;

*REGpointer |= TIM1EN;

But the instruction to set the ARR have no effect on the register even if the ARPE in true.

Posted on May 10, 2017 at 16:42

Hi Dario,

I suggest to you to use CubeMX for peripheral initialization, there is athread with useful information if you keep having the same problem.

https://community.st.com/0D50X00009XkYJ6SAN

Posted on May 10, 2017 at 17:02

But the instruction to set the ARR have no effect on the register even if the ARPE in true.

Maybe because you have the address constant wrong.

The CMSIS-mandated device headers are to supply the constants by the factory.

JW

Posted on May 12, 2017 at 09:17

Thank you to everyone for the tips, but finally I succeeded. Now my waiting function work well. The only strange thing is this: if I do not set the ARR value leaving it to FFFF, and I run the code it stuck on the waiting while in the function and the count is very very slow in fact if I break the programm even after 30 seconds it usually shows a CNT of 24. At that point if I make it run it works properly. Thank you again.

Dario Laezza

Posted on May 29, 2017 at 03:53

This is because you are using 

*REGpointer |= ARR; It should be 

*REGpointer = ARR;