cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152 - Timer interrupt do not work

MLy
Associate II

HI,

I am using STM32L152 on IAR V8.11.2

setup an interrupt IRQ but it does not seem compile since it do not exist in the map file.

once NVIC_EnableIRQ execute, program will halt into BusFault_Handler

Thanks!

/* Includes ------------------------------------------------------------------*/

#include <stddef.h>

#include "stm32l1xx.h"

#include "stdarg.h" 

#include "stdlib.h"

#include "stdio.h"

#include "stm32l1xx_rcc.h"

#include "stm32l1xx_gpio.h"

#include "stm32l1xx_tim.h"

#include "stm32l1xx_syscfg.h"

#include "stm32l1xx_usart.h"

#include "stm32l1xx_pwr.h"

#include "misc.h" 

#ifdef __cplusplus

 extern "C" {

#endif

void TIM3_IRQHandler(void);

#ifdef __cplusplus

 }

#endif

//=============================================================================

// TIM3 Interrupt Handler

//=============================================================================

void TIM3_IRQHandler(void)

{

if(TIM3->SR & TIM_SR_UIF) // if UIF flag is set

 {

 TIM3->SR &= ~TIM_SR_UIF; // clear UIF flag

 }

}

/* Includes ------------------------------------------------------------------*/

#include <stddef.h>

#include "stm32l1xx.h"

#include "stdarg.h" 

#include "stdlib.h"

#include "stdio.h"

#include "stm32l1xx_rcc.h"

#include "stm32l1xx_gpio.h"

#include "stm32l1xx_tim.h"

#include "stm32l1xx_syscfg.h"

#include "stm32l1xx_usart.h"

#include "stm32l1xx_pwr.h"

#include "misc.h" 

int main()

{

 /* reset rcc */

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); 

// RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;

 TIM3->PSC = 23999;     // Set prescaler to 24 000 (PSC + 1)

 TIM3->ARR = 1000;      // Auto reload value 1000

 TIM3->DIER = TIM_DIER_UIE; // Enable update interrupt (timer level)

 TIM3->CR1 = TIM_CR1_CEN;  // Enable timer

 NVIC_EnableIRQ(TIM3_IRQn); // Enable interrupt from TIM3 (NVIC level 

 while(1)

 {

 }

  

}

0 REPLIES 0