Problems with Nucleo-F303RE
Hello, I am using STM32 Workbench Version: 1.13.2.201703061529 with Nucleo_F303RE board (featuring the microcontroller STM32F303RET6).
I work under Windows 7.
I am trying to use the microcontroller Timers and TIM3 in particular. The code I developed initialize TIM3 to generate an interrupt every 1sec and write a string to USART2. The Timer is initially disabled and is enabled when a character on the USART is received. The code for the TIM3 initialization and interrup handler is the following. USART works correctly since I tried without timer. As soon as TIM3 (and the attached interrupt) is enabled the microprocessor hangs and is no more able to receive input from USART. A strange thing is that in the NVIC.IRQChannel field I must insert 29 and not TIM3_IRQn (is not recognized and gives an error) even if the file stm32f30x.h is included at the beginning of main.c
void Initialize_Timer(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_TimeBaseInitTypeDef timerInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
timerInitStructure.TIM_Prescaler = 35999;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 1999;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3, &timerInitStructure);
TIM_ITConfig(TIM3, TIM_IT_Update, DISABLE);
TIM_Cmd(TIM3, DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = 29;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_IRQHandler(void)
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
USART_write_string(“TIM UPDATE”, 1);
}
}