2013-11-19 06:48 PM
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-interrupt2013-11-19 07:16 PM
If you're using C++ be very careful the IRQHandler name isn't getting mangled. Check the .MAP, and linkage in the vector table. Can you trap the interrupt in the debugger?
I might also change the toggling code.2013-11-19 07:46 PM
Hi Clive,
I'm in C and I check the start up assembly file and I confirmed the IRQ handler is correct. I realize my toggle for LEDs needs work. I never see it go into the interrupt in the debugger. It turns one of the LEDs on a stays on. For the ethernet I'm using the lwip stack example programs and it is working.Any help would be appreciated.Thank you,Chris2013-11-20 01:16 AM
Not sure what's behind the function 'tcp_echoclient_connect()' you are calling from within the timer interrupt, but IMHO this could be the culprit.
It is usually not a good idea to call either lengthy functions, or functions that rely on other interrupts to work properly, from within an interrupt.