2011-06-23 09:03 AM
Hi!
I've to program STM32f100R4H6; particularly i've to manage TIM1 interrupt. Below there is my code..Thank you in advance.. -------------------------------------------------------------------------------------------- //In the first part of the main.. void RCC_init(void){ // 1. Clocking the controller from internal HSI RC (8 MHz) RCC_HSICmd(ENABLE); // wait until the HSI is ready while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET); RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); // 2. Enable ext. high frequency OSC RCC_HSEConfig(RCC_HSE_ON); // wait until the HSE is ready // 3. Init PLL RCC_PLLCmd(ENABLE); // wait until the PLL is ready while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); // 4. Set system clock dividers RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5); RCC_ADCCLKConfig(RCC_PCLK2_Div8); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_PCLK1Config(RCC_HCLK_Div2); RCC_HCLKConfig(RCC_SYSCLK_Div1); /*&sharpdefine EMB_FLASH &sharpifdef EMB_FLASH // 5. Init Embedded Flash // Zero wait state, if 0 < HCLK 24 MHz // One wait state, if 24 MHz < HCLK 56 MHz // Two wait states, if 56 MHz < HCLK 72 MHz // Flash wait state FLASH_SetLatency(FLASH_Latency_2); // Half cycle access FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable); // Prefetch buffer FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); &sharpendif // EMB_FLASH */ // 5. Clock system from PLL RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); --------------------------------------------------------------------------------------------- //Function that manage TIM1 void tim1_init(void){ /*-------TIMER START----------*/ TIM_TimeBaseInitTypeDef TIM1_TimeBaseInitStruct; // Timer1 Init // Enable Timer1 clock and release reset RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1,DISABLE); /*-----------------SETTAGGIO PARAMETRI TIMER1----------------*/ // Prescaler=7200 & Period=10000 & Repetition =0-->Trigger event ogni secondo // Prescaler=3600 & Period=10000 & Repetition =0-->Trigger event ogni 0.5 secondi // Prescaler=720 & Period=10000 & Repetition =0-->Trigger event ogni 100ms // Prescaler=6534 & Period=10 & Repetition =0-->Trigger event ogni 1ms /*-----------------------------------------------------------*/ TIM1_TimeBaseInitStruct.TIM_Prescaler = 1; TIM1_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; TIM1_TimeBaseInitStruct.TIM_Period = 1; TIM1_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1; TIM1_TimeBaseInitStruct.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1,&TIM1_TimeBaseInitStruct); // Clear update interrupt bit TIM_ClearITPendingBit(TIM1,TIM_IT_Update); // Enable update interrupt TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE); NVIC_InitTypeDef NVIC_InitStructure; //create NVIC structure NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_TIM16_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // Enable timer counting TIM_Cmd(TIM1,ENABLE); /*---------END TIMER----------*/ } void TIM1_UP_TIM16_IRQHandler(void){ ... } #problem #tim1 #stm32 #timer #interrupt2015-11-05 12:18 PM
Update is the reset/zero event, ie rolls to zero, you yes you'll get that initial interrupt. You'll have to manage that if it's critical to your process. ie use a flag, and ignore the first entry.