cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4Discovery TIM7 with ethernet

csfarnham
Associate II
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 handler

void 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
3 REPLIES 3
Posted on November 20, 2013 at 04:16

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
csfarnham
Associate II
Posted on November 20, 2013 at 04:46

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,

Chris

frankmeyer9
Associate II
Posted on November 20, 2013 at 10:16

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.