cancel
Showing results for 
Search instead for 
Did you mean: 

Timer interrupt incorrect result

patchouling
Associate
Posted on October 13, 2014 at 18:27

Hi everyone.

I need some explain why this code generating not 1KHz TIM2 interrupt.

I have no idea why generating 2KHz in APB1 clock(30MHz) & PPRE1(0b101) & CKD(0b00).

#include ''stm32f2xx.h''

void

TIM2_IRQHandler

()

    {

    TIM2

->

SR

&=~

1

;

    GPIOA

->

ODR

^=

0x00000001

;    

//PA0 Toggle

    }

int

main

()

    {

    RCC

->

AHB1ENR

|=

0x00000001

;  

//PA0 Clock EN

    RCC

->

APB1ENR

|=

0x00000001

;  

//TIM2 Clock EN

    GPIOA

->

MODER

|=

0x00000001

;  

//PA0 Output

   

//

    TIM2

->

PSC

=

10

-

1

;            

//Prescaler //APB1clk/Presclr/fOUT = ARR <=0xFFFF   //PPRE1 101: AHB/4=30MHz

    TIM2

->

ARR

=

3000

-

1

;          

//Period

    TIM2

->

EGR

|=

0x0001

;         

//Update generation

    TIM2

->

DIER

|=

0x0001

;        

//Update interrupt EN

    TIM2

->

CR1

|=

0x0001

;         

//CKD : 0 //Up Counter //Counter EN

   

//

    SCB

->

AIRCR

|=

0x00000300

;    

//Group 7:4 //Sub None

    NVIC

->

IP[

28

]

|=

0xF0

;        

//TIM2 Global Interrupt : Position [28] //Priority group 15

    NVIC

->

ISER[

0

]

|=

0x10000000

//TIM2 Interrupt SET //[28]>>0x05==[0]   //1<<(IRQ_CH&0x1F)

   

while

(

1

){}

    }
2 REPLIES 2
Posted on October 13, 2014 at 18:44

0690X00000605AtQAI.png

Also it's TIMx->SR = ~X, and not TIMx->SR &= ~X

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
patchouling
Associate
Posted on October 13, 2014 at 19:52

Thanks clive1!