Tutorial 5 - LEDs Blinking

STM32F4Discovery Tutorial 5 - Leds Blinking

In this tutorial we will learn how we can connect external electronic components to discovery board. Till now we have written programs that only work on leds present on the discovery board itself. But now we will connect external components with the help of breadboard. We will learn how to work with breadboards. We will then connect external leds to the discovery board using wires and breadboard. And then we will write program to make them blink in a particular pattern.

After completing this tutorial, you can easily connect external electronic components to discovery board like sensors. leds etc. and you will not be limited only to the features available on discovery board.

#include "stm32f4xx.h"

GPIO_InitTypeDef GPIO_Led;

void Delay(__IO uint32_t nCount){
        while(nCount--){
        }
}

int main(void)
{
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

        GPIO_Led.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
        GPIO_Led.GPIO_Mode = GPIO_Mode_OUT;
        GPIO_Led.GPIO_OType = GPIO_OType_PP;
        GPIO_Led.GPIO_Speed = GPIO_Speed_50MHz;

        GPIO_Init(GPIOD, &GPIO_Led);

  while (1)
  {
          GPIO_WriteBit(GPIOD, GPIO_Pin_0, Bit_SET);
          GPIO_WriteBit(GPIOD, GPIO_Pin_3, Bit_RESET);
          Delay(16800000);
          GPIO_WriteBit(GPIOD, GPIO_Pin_1, Bit_SET);
          GPIO_WriteBit(GPIOD, GPIO_Pin_0, Bit_RESET);
          Delay(16800000);
          GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_SET);
          GPIO_WriteBit(GPIOD, GPIO_Pin_1, Bit_RESET);
          Delay(16800000);
          GPIO_WriteBit(GPIOD, GPIO_Pin_3, Bit_SET);
          GPIO_WriteBit(GPIOD, GPIO_Pin_2, Bit_RESET);
          Delay(16800000);
  }
}