I wish use the timer 15 on a Blue Pill, with STM32duino IDE based on Roger's Clark core. I would use this timer for internal loop in my code, without GPIO action.
My informations are based on RM0041 (STM) and i prefer, for this, "bare metal" code.
I've seen that it's impossible to modify RCC_APB2ENR register ( RM0041 §6.3.7 p90) that is always fixed too 0x4E3D.
I use the following code :
Code: Select all
noInterrupts();
//Enable l'horloge du bus TIM1
*APB2_ENR |= (1<<16); //Set bit 16 (TIM15EN)
*APB2_RSTR |= (1<<16);
*APB2_RSTR &= ~(1<<16);
interrupts();
//Enable bus TIM15
*APB2_ENR |= (1<<16); //Set bit 16 (TIM15EN)
//Stop comptage
*TIM15_CR1 &= ~(1<<0); //Reset bit 0 (CEN)
//Buffer CNT
*TIM15_CR1 |= (1<<7); //set bit 7 (ARPE)
//Divise CK_INT (72MHz) par 36000 (-> 2000Hz)
*TIM15_PSC = 0x8CA0; //Division de CK_INT
//Pré-load du compteur à la tempo ( 1000 -> 0.5s)
*TIM15_ARR = 0x03E8;
//Enable CNT p333
*TIM15_CR1 |= (1<<0); //Set bit 0 (CEN)
RM0041 indicate that STM32F103C8T6 is a medium density hardware and have timers 15,16,17 ( but not 12,13,14 !).
So, i have 2 questions :
**1 - why STM32duino set, by default, RCC_APB2ENR = 0x4E3D ?
**2 - why i can't modify this register ?
Code: Select all
Enter in Setup() - APB2_ENR = 4E3D APB1_ENR = = 7 PSC = 1 ARR = FFFF
After Init TIM15() - APB2_ENR = 4E3D APB1_ENR = = 7 PSC = 8CA0 ARR = 3E8