AnsweredAssumed Answered

STM32F0 timer as counter to count external pulses

Question asked by R V on Oct 16, 2017
Latest reply on Dec 31, 2017 by John Craven


I am using STM32F051R8T6 to simply use the timer to count external pulses. I have referred the reference manual RM0091 and have used the function given in the Standard peripheral library. I am using PA9 to receive the external pulses, as per the code example given in the datasheet. I am yet to figure out what interrupt should be used to capture the value and how should I get the value of counts?

Library used: Standard Peripheral Library

Reference Manual: RM0091

Section referred: TIMER1

Sub section: External clock source mode 1

Any inputs to complete the interrupt part will be really useful.

(Either the documentation provided is really poor or may be its complex enough for a beginner like me to understand. It is really tiresome to do simple tasks such as counting using timer peripheral by referring the entire manual and still not getting any idea as in whole. I agree that I am not expert in the field, but it still should be well documented if it needs to be popular and widely acceptable.) Thank you.


The code so far:


int main(void)

void CounterConfig()
    //Enable Peripheral Clock on Timer 1




void GpioConfig(void)
    GPIO_InitTypeDef GPIO;
    GPIO.GPIO_Pin = GPIO_Pin_9;
    GPIO.GPIO_Mode = GPIO_Mode_AF;
    GPIO.GPIO_OType = GPIO_OType_PP;
    GPIO.GPIO_Speed = GPIO_Speed_2MHz;