Step by Step Guidance on How to Implement a Sequence Where Three LEDs Blink in Various Combinations (such As 001,010,011,...)

by Jasleen_kaur in Circuits > Microcontrollers

114 Views, 0 Favorites, 0 Comments

Step by Step Guidance on How to Implement a Sequence Where Three LEDs Blink in Various Combinations (such As 001,010,011,...)

WhatsApp Image 2024-04-24 at 20.26.53_41452763.jpg

Welcome to our exciting tutorial on how to unleash the full potential of your STM32 Black Pill board using STM32CubeIDE! In this comprehensive, step-by-step guide, we will walk you through the process of making three external LEDs blink in different combinations (such as 001, 010, 011, and more).

Whether you are a professional looking for a clear and concise walkthrough or an enthusiast eager to delve into the world of microcontroller programming, this tutorial is perfect for you. We will cover everything you need to know, starting from setting up your development environment to writing efficient code for LED management.

By the end of this tutorial, you will not only have a solid understanding of embedded development but also gain the skills necessary to tackle even the most complex projects. With precision and professionalism, we will empower you to bring your projects to the next level.

Get ready to unlock the true potential of your STM32 Black Pill board and embark on an exciting journey into the realm of microcontroller programming. Let's dive in and create magic with your projects!

Supplies

  1. STM32CubeIDE
  2. STM32 Black Pill
  3. STM32CubeProgrammer
  4. C-Type cable
  5. Breadboard
  6. 3 LEDs
  7. Jumper wires

Creating a New Project

Screenshot 2024-04-24 194630.png
  • Open STM32CubeIDE>Goto files>click New>select STM32 Project

Adding MCU/MPU Selector Features for STM32 Project

Screenshot 2024-04-24 004518.png
Screenshot 2024-04-24 195859.png
Screenshot 2024-04-24 195807.png
  • Enter the Commerical Number of STM32 you want to work with( used Commerical Number in this project:STM32F401CCU6)
  • Select the required type of configuration of STM32.
  • Then click next.
  • A dialogue box appears >type the name of the project
  • The project file is created to work on it.


Pinout Configurations

Screenshot 2024-04-24 200006.png
Screenshot 2024-04-24 200023.png
Screenshot 2024-04-24 200041.png
  • Select RCC from System Core.
  • Select the Cereamic/crystal response in High speed clock.
  • Some configurations wlll be added ,i.e,RCC_OSC_IN & RCC_OSC_OUT ON STM32 board of cubeide.
  • Select the Pins for output .(here I used PA10,PA11,PA12).


Clock Configuration

Screenshot 2024-04-24 200206.png
  • Select clock configuration.
  • Select HSE and PLLCLK in PLL Source MUX & System Clock MUX respectively.
  • Then select resolve clock issues


Generating the Code

Screenshot 2024-04-24 200254.png
  • Select the project from dialogue box.
  • Select generate code option from it.
  • The code gets generated.


Creating .Ioc File

Screenshot 2024-04-24 200406.png
Screenshot 2024-04-24 200430.png
Screenshot 2024-04-24 200502.png
  • Select the file you working on (from the left side)>right click on it.
  • A option box appears>select properties.
  • Then the dialogue box opens >select the C/C++ Build (from left side of it).
  • Select settings>MCU Post build Ouput
  • Choose the options shown in the image.
  • Then apply and close.
  • The .ioc file is created.


Main.c

Screenshot 2024-04-24 200552.png
Screenshot 2024-04-24 200602.png
  • Select the core from the File .
  • Go to Src>select main.c.
  • Main.c gets open to write code.(A code is generated already to help you in the configuration and to identify pin numbers you selected as output pins)


Writing Code

Screenshot 2024-04-24 200656.png
Screenshot 2024-04-24 200722.png
Screenshot 2024-04-24 200730.png
Screenshot 2024-04-24 200741.png
  • Write the code in while loop.

Code:

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

HAL_Delay(300);


HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, 0);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 1);

HAL_Delay(300);

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, 0);

Debug the Code

Screenshot 2024-04-24 200908.png
Screenshot 2024-04-24 200940.png
Screenshot 2024-04-24 200920.png
  • Select Build >select option 1.debug


Copying the Path Of.elf File

Screenshot 2024-04-24 201051.png
WhatsApp Image 2024-04-24 at 20.12.46_6c217bc0.jpg
  • After debuging the ;if any error arises then remove all the error and if no error comes then go to .ioc file.
  • Select .ioc file right click on it ,a option box appears.
  • Select show in>system explorer.
  • Files will be opened.
  • Select the .elf file and copy its path.


Adding the .elf on STM32CubeProgramer

Screenshot 2024-04-24 201656.png
Screenshot 2024-04-24 201711.png
Screenshot 2024-04-24 201721.png
  • Open the STM32CubeProgrammer.
  • Select the Open file option >paste the path copied of .elf file there.
  • File is added.


Breadboard Connection

WhatsApp Image 2024-04-24 at 20.26.53_f4e08c18.jpg
  • Place the Stm32 on breadboard.
  • Connect the LEDs with STM32 by the pins given in STM32CubeIDE.
  • Ground the LEDs with the ground pin from STM32.


Connect the STM32

Screenshot 2024-04-24 202245.png
  • Connect the STM32 Black pill with Laptop.
  • Connect it with STM32CubeProgrammer by USB.
  • BOOT the STM32 to connect it.
  • After connecting click on Connect


Download the File

Screenshot 2024-04-24 201740.png
Screenshot 2024-04-24 201751.png
  • Goto Download>paste the copied of .elf file here also
  • Click on Start Automatic Mode.


LEDs Start Blinking According to Combinations

WhatsApp Image 2024-04-24 at 20.26.53_89e69efa.jpg
WhatsApp Image 2024-04-24 at 20.26.53_41452763.jpg
  • Disconnect the STM32.
  • Then connect again and you will see that the LEDs are blinking in the combination of 001,010,011,100,101,110,111.


Downloads