AnsweredAssumed Answered

TIM8 Toggle STM32F4

Question asked by PeterLup2 on Jun 26, 2015
Latest reply on Jul 1, 2015 by PeterLup2
Hi,

I'm trying to toggle some pins when timer 8 overflows.

The problem I get is that I don´t see the pins toogle but I can see the timer counting on the debugger, so I think I might be missing some mistereous configuration on the GPIO.

I'm using all 4 channels just for testing and I put a pulse value of half the timer period for testing aswell.

The code I have so far:

void TIM8_Init(void){
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
    TIM_OCInitTypeDef TIM_OCInitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
     
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8 ,ENABLE);
     
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_High_Speed;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOC,&GPIO_InitStructure);
 
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource6 ,GPIO_AF_TIM8);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource7 ,GPIO_AF_TIM8);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource8 ,GPIO_AF_TIM8);
    GPIO_PinAFConfig(GPIOC, GPIO_PinSource9 ,GPIO_AF_TIM8);
     
  TIM_TimeBaseStructure.TIM_Period = 100;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
     
    //Channel 1
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
    TIM_OCInitStructure.TIM_Pulse = 50;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
  TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCPolarity_High;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
  TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
     
    TIM_OC1Init(TIM8, &TIM_OCInitStructure);
    TIM_OC2Init(TIM8, &TIM_OCInitStructure);
    TIM_OC3Init(TIM8, &TIM_OCInitStructure);
    TIM_OC4Init(TIM8, &TIM_OCInitStructure);
     
  //TIM_DMACmd(TIM8, TIM_DMA_Update, ENABLE );  /* Enable TIM8_Updates DMA Requests     */
    //SET COUNTER
     
    TIM8->CR1 = 0x1;
}

Thanks :)

Outcomes