CODE
RCC->APB1ENR |= RCC_APB1ENR_TIM4EN;
// 4й канал таймера 4 =pb9
//1
TIM4->CCMR2 &=~ TIM_CCMR2_CC4S_0;//0
TIM4->CCMR2 |= TIM_CCMR2_CC4S_1;//1
//3
TIM4->CCER &=~ TIM_CCER_CC4P;//0
//4
TIM4->SMCR |= TIM_SMCR_SMS_0;//1
TIM4->SMCR |= TIM_SMCR_SMS_1;//1
TIM4->SMCR |= TIM_SMCR_SMS_2;//1
//5
TIM4->SMCR |= TIM_SMCR_TS_0;//1
TIM4->SMCR |= TIM_SMCR_TS_1;//1
TIM4->SMCR &=~ TIM_SMCR_TS_2;//0
TIM4->CR1 = TIM_CR1_CEN; //разрешаем счет таймера
// 4й канал таймера 4 =pb9
//1
TIM4->CCMR2 &=~ TIM_CCMR2_CC4S_0;//0
TIM4->CCMR2 |= TIM_CCMR2_CC4S_1;//1
//3
TIM4->CCER &=~ TIM_CCER_CC4P;//0
//4
TIM4->SMCR |= TIM_SMCR_SMS_0;//1
TIM4->SMCR |= TIM_SMCR_SMS_1;//1
TIM4->SMCR |= TIM_SMCR_SMS_2;//1
//5
TIM4->SMCR |= TIM_SMCR_TS_0;//1
TIM4->SMCR |= TIM_SMCR_TS_1;//1
TIM4->SMCR &=~ TIM_SMCR_TS_2;//0
TIM4->CR1 = TIM_CR1_CEN; //разрешаем счет таймера
Figure 157. TI2 external clock connection example
For example, to configure the upcounter to count in response to a rising edge on the TI2
input, use the following procedure:
1. Configure channel 2 to detect rising edges on the TI2 input by writing CC2S = ‘01’ in
the TIMx_CCMR1 register.
2. Configure the input filter duration by writing the IC2F[3:0] bits in the TIMx_CCMR1
register (if no filter is needed, keep IC2F=’0000’).
3. Select the rising edge polarity by writing CC2P=’0’ and CC2NP=’0’ in the TIMx_CCER
register.
4. Configure the timer in external clock mode 1 by writing SMS=’111’ in the TIMx_SMCR
register.
5. Select TI2 as the trigger input source by writing TS=’110’ in the TIMx_SMCR register.
6. Enable the counter by writing CEN=’1’ in the TIMx_CR1 register.
а вот как я пробовал сделать через библы но тоже не получается(
CODE
// /* TIM4 clock enable */
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
//
// TIM_ICInitTypeDef TIM_ICInitStructure;
// TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
// TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
// TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;
// TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
// TIM_ICInitStructure.TIM_ICFilter = 0x0;
// TIM_ICInit(TIM4, &TIM_ICInitStructure);
//
// /* TIM enable counter */
// TIM_Cmd(TIM4, ENABLE);
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
//
// TIM_ICInitTypeDef TIM_ICInitStructure;
// TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
// TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
// TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI;
// TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
// TIM_ICInitStructure.TIM_ICFilter = 0x0;
// TIM_ICInit(TIM4, &TIM_ICInitStructure);
//
// /* TIM enable counter */
// TIM_Cmd(TIM4, ENABLE);