2017-05-09 08:35 AM
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-f2017-05-09 08:48 AM
I forgot to say that I'm using IAR Embedded Workbench.
2017-05-09 08:59 AM
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.
may be of assistance to you as well.2017-05-09 11:48 AM
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.
2017-05-10 07:42 AM
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.
2017-05-10 10:02 AM
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
2017-05-12 02:17 AM
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
2017-05-28 08:53 PM
This is because you are using
*REGpointer |= ARR; It should be
*REGpointer = ARR;