Search
#include "stm32f4xx.h" void initInput(void){ RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN; // PA0 - alternate function for Input Capture Mode GPIOA->PUPDR |= GPIO_PULLUP << GPIO_PUPDR_PUPD0_Pos; GPIOA->MODER |= GPIO_MODE_AF_PP << GPIO_MODER_MODER0_Pos; GPIOA->AFR[0] |= GPIO_AF1_TIM2 << GPIO_AFRL_AFSEL0_Pos; } void initTIM2(void){ RCC->APB1ENR |= RCC_APB1ENR_TIM2EN; // povoleni hodin do bloku TIM2 TIM2->PSC = 1600; TIM2->ARR = 10000; // input capture enable for PA1 TIM2->CCMR1 |= 0x01 << TIM_CCMR1_CC1S_Pos; // set TI1 as input mode TIM2->CCER |= TIM_CCER_CC1P; // falling edge TIM2->CCER |= TIM_CCER_CC1E; // Capture enabled } int main(void){ initInput(); initTIM2(); while(1){ // process data from TIM2->CCR1 } }