cancel
Showing results for 
Search instead for 
Did you mean: 

Timer 5 Setup

cwparker
Associate II
Posted on May 28, 2013 at 22:49

I'm just stering with the STM324f Discovery board and am trying to get timer 5 setup as a free running 1us timer that I can access in my code for timing. No matter what I do, I can't get TIM5->CNT to change from zero. Any idea what I'm doing wrong? Here's the relevent code in main():

/* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */

#define

PLL_M 8

#define

PLL_N 336

/* SYSCLK = PLL_VCO / PLL_P */

#define

PLL_P 2

/* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */

#define

PLL_Q 7

int

main()

{

  SystemInit();

  TIM5->

CR1

= 0;

// disable timer 5

  TIM5->

DIER

= 0;

// no interrupts

  TIM5->

CNT

= 0;

// reset timer value

  TIM5->

PSC

= (PLL_N / PLL_P) - 1;

//

prescaler

  TIM5->

ARR

= 0xFFFFFFFF;

// reload value

  TIM5->

EGR

= 1;

TIM5->

CR1

= TIM_CR1_CEN;

// enable timer 5

RCC->

APB1ENR

|= RCC_APB1ENR_TIM5EN;

TIM5->

SR

= 0;

// reset flags

1 REPLY 1
Posted on May 28, 2013 at 23:12

First rule of synchronous logic, have a clock.

Turn ON the clock first, otherwise the register writes won't work.

RCC->

APB1ENR

|= RCC_APB1ENR_TIM5EN;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..