AnsweredAssumed Answered

STM32F4 Discovery timer syncronization

Question asked by loeser.leon on Mar 30, 2015
Latest reply on Mar 31, 2015 by Clive One
I am currently trying to generate a squarewave on A8 with TIM1 (50% duty PWM1) and use TIM2 as a slave to trigger an interrupt every 4096th tick (this is used to reset the counter of an LED driver and to push new data).
The problem is, that the interrupt is once triggered before the timers are even initialized (breakpoint) and then never again. My code:

Timer initialization:
01.RCC->APB1ENR |= RCC_APB1Periph_TIM2;
02.RCC->APB2ENR |= RCC_APB2Periph_TIM1;
03. 
04.TIM_SelectMasterSlaveMode(TIM1, TIM_MasterSlaveMode_Enable);
05.TIM_SelectOutputTrigger(TIM1, TIM_TRGOSource_Reset);
06.TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_External1);
07.TIM_SelectInputTrigger(TIM2, TIM_TS_ITR0);
08. 
09.TIM_TimeBaseInitTypeDef timerInitStructure;
10.timerInitStructure.TIM_Prescaler = 2 - 1;
11.timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
12.timerInitStructure.TIM_Period = 4 - 1;
13.timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
14.timerInitStructure.TIM_RepetitionCounter = 0;
15.TIM_TimeBaseInit(TIM1, &timerInitStructure);
16. 
17.timerInitStructure.TIM_Prescaler = 2 - 1;
18.timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
19.timerInitStructure.TIM_Period = 2048 - 1;
20.timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
21.timerInitStructure.TIM_RepetitionCounter = 0;
22.TIM_TimeBaseInit(TIM2, &timerInitStructure);
23. 
24.NVIC_InitTypeDef nvicStructure;
25.nvicStructure.NVIC_IRQChannel = TIM2_IRQn;
26.nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
27.nvicStructure.NVIC_IRQChannelSubPriority = 1;
28.nvicStructure.NVIC_IRQChannelCmd = ENABLE;
29.NVIC_Init(&nvicStructure);
30.TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
31. 
32.TIM_OCInitTypeDef ocInitStruct;
33.ocInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
34.ocInitStruct.TIM_OutputState = TIM_OutputState_Enable;
35.ocInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
36.ocInitStruct.TIM_Pulse = 2;
37.TIM_OC1Init(TIM1, &ocInitStruct);
38.TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
39. 
40.GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
41.TIM_Cmd(TIM1, ENABLE);
42.TIM_Cmd(TIM2, ENABLE);

ISR:
01.void TIM2_IRQHandler()
02.{
03.    if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
04.    {
05.    TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
06.    GPIO_SetBits(BLANK_Port, BLANK_Pin);
07.    GPIO_ResetBits(BLANK_Port, BLANK_Pin);
08.    }
09.}

What did I do wrong?
are TIM1 and 2 not syncable with each over?

Outcomes