cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RB Enabling TIM Peripheral Clocks

jdsus
Associate

I recently learned about Timers and I looked through the RM and DS of the MCU and I am trying to set up my TIM6 but it seems that I cannot even enable any Timer peripheral clocks in the RCC_APB1ENR register at all, I can write to bits 31-11 but bits 8-0 are stuck at zero and the bits 8-0 are the TIMx EN bits. I am lost and I couldn't find anything on google. I am fairly new to using microcontrollers and I know that the rule of thumb is that you must enable the peripheral clock before you can edit their registers, so this means enabling the TIM clock for the specific timer should be the first thing I do but it seems I can't even enable it. Any help would be greatly appreciated.

1 REPLY 1
Sarra.S
ST Employee

Hello @jdsus

TIMx EN bits are rw, you should be able to write 1 to the TIM6EN bit

// Enable TIM6 clock
RCC->APB1ENR |= (1 << 4); //TIM6EN is bit 4 in RCC_APB1ENR

// Wait for 2 clock cycles (this is a simple way to ensure the delay)
__NOP();
__NOP();

I'm adding NOPs for synchronization purpose, after the enable bit is set, there is a 2-clock-cycle delay before the clock becomes active.

Also, in general, if you want to learn about timers, you can start from General-purpose timer cookbook for STM32 microcontrollers.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.