FIRMWARE DEVELOPER
Embedded Systems

Stm32F4 Discovery board Led blink using Timer Interrupt

____________________________________________________________________________________________________

In last tutorial ,study how to use GPIO pins to blink led present on the Stm32f4 Discovery Board. In this tutorial ,study how to use time as a interrupt to blink led on Stm32f4 Discovery Board.

Stm32f4 controller built with several type of Timer with following features:-

  1. General-purpose timers are used in any application for output compare (timing and delay generation) e.g delay in led blink,sensor interfacing, encoder data reading.
  2. Advanced timers: In addition to general purpose functions, they include several features related to motor control and digital power conversion applications.
  3. Low-power timers are simpler than general purpose timers and their advantage is the ability to continue working in low-power modes and generate a wake-up event.
  4. High-resolution timers are specialized timer peripherals designed to drive power
    conversion in lighting and power source applications.
  5. Basic timers have no input/outputs and are used either as time base timers or for triggering the DAC peripheral.

Timer Features of Stm32f4 controller

To blink the led using timer on stm32f4 discovery board first initialize Led pins present on the discovery board.

 

After that we initialize the timer 2:-

 

After initializing timer 2 ,configure timer  2 as an  interrupt:-

After that put the code which you want to do after an interval (here we put led blink function in ISR of timer 2).

 

A sample example of Stm32F4 Discovery board Led blink using Timer Interrupt as follows

 

Dependency  to compile the program as follows:-

  1. stm32f4xx.h
  2. stm32f4xx_gpio.h
  3. stm32f4xx_rcc.h
  4. fm_stm32f4_led.h
  5. fm_stm32f4_tim2.h

click to get fm_stm32f4_led.h

Timer 2 library

download (1)

  1. fm_stm32f4_led.h function

      2. fm_stm32f4_led.c function

3. fm_stm32f4_tim2.c function

3. fm_stm32f4_tim2.h function

Complete project compiled in coocox is given below

download (1)

  1. Led blinking  using timer interrupt on stm32f4 Discovery Board