STM32 timer3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-13 1:16 AM
Hi everyone. I wrote this code to run the stm32f0 timer3, which toggle 2 LEDs at a time, but it doesn't work.
Can anyone please help meØŸ
void TIM3_Init()
{
TIM_TimeBaseInitTypeDef TIM3_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM3_InitStructure.TIM_Prescaler = 359;
TIM3_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM3_InitStructure.TIM_Period = 199;
TIM3_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM3_InitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM3, &TIM3_InitStructure);
TIM_Cmd(TIM3, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
}
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){
TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
GPIOB->ODR ^= GPIO_Pin_2|GPIO_Pin_3;
}
}
Labels:
- Labels:
-
STM32F0 Series
-
TIM
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-13 1:33 AM
Read out and check/post the TIM and relevant GPIO registers content.
JW
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-06-13 1:00 PM
Line:
RCC_APB1PeriphResetCmd(RCC_APB1Periph_TIM3, ENABLE);
is wrong. You want call function:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
to enable clock ! For next similar issues i suggest to do thist "checklist":
- Check if "non working" peripheral has clock enabled
- Check if used GPIOs has clock enabled
- Check if used GPIOs are configured as proper alternate function
- Check if you are looking at right GPIOs
