AnsweredAssumed Answered

STM32F0308 TIM3 Interrupt not triggering

Question asked by Tom Power on Aug 16, 2017
Latest reply on Aug 16, 2017 by Clive One

Hi, 

 

I am having trouble getting an interrupt working with the TIM3, roughly following this guide: 

 

http://www.micromouseonline.com/2016/02/03/tim3-arr-regular-interrupts-stm32f4/ 

 

but adapting for the STM32F0308. 

 

TIM3 is running, and reloading (verified with the commented out code in the main loop ), but the interrupt flag does not appear to be triggering. 

 

Any help would be greatly appreciated, my code is below:


#include "stm32f0xx.h"

 

#define BSRR_VAL        0x0300

 

volatile uint16_t count = 0;


void timer_interrupt_init( void );
void timer_init( void );
void timer_start( void );
void timer_interrupt_enable( void );
void leds_init( void );

 

/***********************************************************************************************/

 

void timer_interrupt_init( void )
{
NVIC_InitTypeDef NVIC_InitStructure;
/*Enable timer global interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );
}

 

/***********************************************************************************************/

 

void timer_init( void )
{

/*  Set timer to 1kHz and reload at 1Hz */
uint16_t prescaler = 23999; 
uint16_t reload = 1000; 

RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3, ENABLE );
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

/* Set everything back to default values */
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );

/* Changes from defaults */
TIM_TimeBaseStructure.TIM_Period = reload;
TIM_TimeBaseStructure.TIM_Prescaler = prescaler;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
}

 

/***********************************************************************************************/

 

void timer_start( void )
{
TIM_Cmd( TIM3, ENABLE );
}

 

/***********************************************************************************************/

 

void timer_interrupt_enable( void )
{
/* Clear interrupt flags */
TIM_ClearITPendingBit( TIM3, TIM_IT_Update );
/* Put counter into known state */
TIM_SetCounter( TIM3, 0 );
TIM_ITConfig( TIM3, TIM_IT_Update, ENABLE );
}

 

/***********************************************************************************************/

 

void leds_init( void )
{
RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOC, ENABLE );

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_StructInit( &GPIO_InitStructure );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init( GPIOC, &GPIO_InitStructure );
}

 

/***********************************************************************************************/

 

void TIM3_IRQHandler( void )
{
if ( count == 0 )
{
GPIOC->BSRR = BSRR_VAL;
count = 1;
}
else
{
GPIOC->BRR = BSRR_VAL;
count = 0;
}
TIM_ClearITPendingBit( TIM3, TIM_IT_Update );
}

 

/***********************************************************************************************/

 

int main(void)
{
uint16_t CurrentTimerVal;
timer_init();
timer_interrupt_init();
timer_start();
timer_interrupt_enable();
leds_init();
while (1)
{
//CurrentTimerVal = TIM_GetCounter( TIM3 );

//if ( CurrentTimerVal > 500 )
// GPIOC->BSRR = BSRR_VAL;
//else
// GPIOC->BRR = BSRR_VAL;
}
}

Outcomes