cancel
Showing results for 
Search instead for 
Did you mean: 

problem with SlaveMode and interrupt

matthias23
Associate II
Posted on February 06, 2014 at 14:06

Hi,

I need help with my Stm32F4 In this example I want to clock Tim4 with Tim2 using the slave mode. This is working fine! But when I want to use Tim4 to rise an update-interrupt this line stops the MCU. Somewhere in the 2000 pages of the reference manual must be a hint why this happens but I cannot find it!

void
TIM_Test()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM4_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
nvicStructure.NVIC_IRQChannelSubPriority = 1;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
/* ---------------------------------------------------------------
TIM2 Configuration:
--------------------------------------------------------------- */
TIM_DeInit( TIM2 );
/* Time base configuration */
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
TIM_TimeBaseStructure.TIM_Period =42000000;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
// TIM2 als master für TIM4 über ITR1
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
TIM_ARRPreloadConfig(TIM2, ENABLE);
/* ---------------------------------------------------------------
TIM4 Configuration:
--------------------------------------------------------------- */
//PD14 TIM4_CH3 in Slave Toggle mode
TIM_DeInit( TIM4 );
/* Time base configuration */
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
TIM_TimeBaseStructure.TIM_Period =100;
TIM_TimeBaseStructure.TIM_Prescaler =0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
//Slave Mode
TIM_SelectSlaveMode(TIM4, TIM_SlaveMode_External1);
//Rising edges of the selected trigger (TRGI) clock the counter
TIM_SelectInputTrigger(TIM4, TIM_TS_ITR1);
// TIM enable counter
TIM_Cmd(TIM2, ENABLE);
TIM_Cmd(TIM4, ENABLE);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
}

The last line stops the MCU...but why?? #slavemode-interrupt
3 REPLIES 3
Posted on February 06, 2014 at 14:32

Where is your ISR?

JW
matthias23
Associate II
Posted on February 06, 2014 at 14:38

void
TIM4_IRQnHandler(
void
){
TIM_ClearITPendingBit(TIM4,TIM_IT_Update);
//GPIO_ToggleBits(GPIOA,GPIO_Pin_6);
GPIO_ToggleBits(GPIOC,GPIO_Pin_13);
}

Posted on February 06, 2014 at 15:03

Try

void TIM4_IRQHandler(void) {

JW