Question
STM32F4Discovery TIM7 with ethernet
Posted on November 20, 2013 at 03:48
Hi everybody. I can't seem to get a basic timer to work. I've got it set for a 1 sec interrupt but it seems to never go into the interrupt. I've configured the clocks correctly and changed the header file to 8 MHz HSE PLL. Here is my timer config code with the interrupt. One led is suppose to go on and the other goes off and vice versa when the interrupt is called.
//timer config&sharpinclude ''functions.h''&sharpinclude ''stm32f4_discovery.h''&sharpinclude ''stm32f4xx.h''GPIO_InitTypeDef GPIO_InitStructure;TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;void timerSetup(void){ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); GPIO_StructInit(&GPIO_InitStructure); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOD,&GPIO_InitStructure); NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM7_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock/16800)-1; //10 kHz clock TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 10000-1; //10000 periods for 1 Hz TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure); TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE); TIM_Cmd(TIM7, ENABLE); }//inerrupt handlervoid TIM7_IRQHandler(void){ if (TIM_GetFlagStatus(TIM7, TIM_FLAG_Update) != RESET) { count++; if((GPIO_ReadOutputDataBit(GPIOD, 15) == 0)&&(GPIO_ReadOutputDataBit(GPIOD, 14)) == 1) { GPIO_WriteBit(GPIOD, GPIO_Pin_15, Bit_SET); GPIO_WriteBit(GPIOD, GPIO_Pin_14, Bit_RESET); } else if((GPIO_ReadOutputDataBit(GPIOD, 15) == 1)&&(GPIO_ReadOutputDataBit(GPIOD, 14)) == 0) { GPIO_WriteBit(GPIOD, GPIO_Pin_15, Bit_RESET); GPIO_WriteBit(GPIOD, GPIO_Pin_14, Bit_SET); } else { GPIO_WriteBit(GPIOD, GPIO_Pin_15, Bit_SET); GPIO_WriteBit(GPIOD, GPIO_Pin_14, Bit_RESET); } tcp_echoclient_connect(); if(count >= 899) //if 15 minutes past turn on motor { count = 0; GPIO_WriteBit(GPIOD, GPIO_Pin_13, Bit_SET); } if(count >= 59) { GPIO_WriteBit(GPIOD, GPIO_Pin_13, Bit_RESET); } TIM_ClearITPendingBit(TIM7, TIM_IT_Update); } } #stm32f4-timer-tim7-interrupt