void RemoteInit() { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBase_InitStructure; TIM_ICInitTypeDef TIM_ICInitStructure; TIM_OCInitTypeDef TIM_OC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Define settings of Input-Pin TIM3CH1 (PC6)*/ GPIO_InitStructure.GPIO_Pin = ppmPin; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(ppmPort, &GPIO_InitStructure); GPIO_PinAFConfig(ppmPort, GPIO_PinSource6, GPIO_AF_TIM3); /* Define basic Timer settings * -> 84.000.000 / 28 = 3.000.000 (1s = 3.000.000 Ticks) -> (1ms = 3.000 Ticks) * -> 45000 / 3000 = 15ms (Überlauf nach 15ms) */ TIM_TimeBase_InitStructure.TIM_ClockDivision = 0; TIM_TimeBase_InitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBase_InitStructure.TIM_Prescaler = 27; TIM_TimeBase_InitStructure.TIM_Period = 44999; TIM_TimeBaseInit(TIM3, &TIM_TimeBase_InitStructure); /* SlaveModeReset: Rising edge of the selected trigger input (TRGI) * reinitalize counter and update register! * -> SlaveModeTrigger: TRIGGER_FILTERED_TI1 */ TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset); TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1); /* Enable the Master/Slave Mode */ TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable); /* InputCapture 1 Rising-Edge * DirectTI (PWM on TIM3CH1) */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x3; TIM_ICInit(TIM3, &TIM_ICInitStructure); /* InputCapture 2 Falling-Edge * IndirectTI (PWM on TIM3CH1) * Root Channel2 on CH1 */ TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Falling; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_IndirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x3; TIM_ICInit(TIM3, &TIM_ICInitStructure); /* OutputCompare (Output is independent from the compare result) * compareValue: 9000 (3ms) * OutputChannel 3 */ TIM_OC_InitStructure.TIM_OCMode = TIM_OCMode_Inactive ; TIM_OC_InitStructure.TIM_Pulse = 8999; TIM_OC3Init(TIM3, &TIM_OC_InitStructure); TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); /* Enable Auto-Reload-Register */ TIM_ARRPreloadConfig(TIM3, ENABLE); /* Configures the TIM3 Update Request Interrupt source (SETS the CR1->URS bit)*/ TIM_UpdateRequestConfig(TIM3,TIM_UpdateSource_Regular); /* Enable specific Timer-Interrupts */ TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE); TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE); //TIM_ITConfig(TIM3, TIM_IT_CC3, ENABLE); Not needed!!! Only Flag-State interesting /* TIM3 Enable Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0E; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0E; NVIC_Init(&NVIC_InitStructure); /* Enable Timer */ TIM_Cmd(TIM3, ENABLE); /* Initializing Values */ RemoteTimerInit(); validRemoteData = false; initializationState = NOT_INITIALIZED; }