Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Configuration function */
- void timer_config(void)
- {
- TIM_TimeBaseInitTypeDef tim;
- NVIC_InitTypeDef nvic;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
- #ifdef 1
- /* Results in a period of 10.33 ms */
- tim.TIM_Prescaler = 59999;
- tim.TIM_Period = 28;
- #else
- /* Results in a period of 10.007 ms */
- tim.TIM_Prescaler = 1249;
- tim.TIM_Period = 1344;
- #endif
- tim.TIM_CounterMode = TIM_CounterMode_Up;
- tim.TIM_ClockDivision = TIM_CKD_DIV1;
- TIM_TimeBaseInit(TIM9, &tim);
- nvic.NVIC_IRQChannel = TIM1_BRK_TIM9_IRQn;
- nvic.NVIC_IRQChannelPreemptionPriority = 0;
- nvic.NVIC_IRQChannelSubPriority = 0;
- nvic.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&nvic);
- TIM_ITConfig(TIM9, TIM_IT_Update, ENABLE);
- TIM_Cmd(TIM9, ENABLE);
- }
- /* TIM9 ISR */
- void TIM1_BRK_TIM9_IRQHandler(void)
- {
- GPIOC->ODR |= GPIO_Pin_0;
- TIM9->SR &= ~TIM_IT_Update;
- /* Minor ISR operations. Only array access and subtractions */
- GPIOC->ODR &= ~GPIO_Pin_0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement