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,...)
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
- STM32CubeIDE
- STM32 Black Pill
- STM32CubeProgrammer
- C-Type cable
- Breadboard
- 3 LEDs
- Jumper wires
Creating a New Project
- Open STM32CubeIDE>Goto files>click New>select STM32 Project
Adding MCU/MPU Selector Features for STM32 Project
- 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
- 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
- Select clock configuration.
- Select HSE and PLLCLK in PLL Source MUX & System Clock MUX respectively.
- Then select resolve clock issues
Generating the Code
- Select the project from dialogue box.
- Select generate code option from it.
- The code gets generated.
Creating .Ioc File
- 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
- 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
- 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
- Select Build >select option 1.debug
Copying the Path Of.elf File
- 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
- Open the STM32CubeProgrammer.
- Select the Open file option >paste the path copied of .elf file there.
- File is added.
Breadboard Connection
- 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
- 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
- Goto Download>paste the copied of .elf file here also
- Click on Start Automatic Mode.
LEDs Start Blinking According to Combinations
- 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.