A Guide to Get Started With STM32 Black Pill and STM Cube IDE to Implement a Sequence Where Three LEDs Blink in Various Combinations.
by vanshika4566_be23 in Circuits > Microcontrollers
131 Views, 0 Favorites, 0 Comments
A Guide to Get Started With STM32 Black Pill and STM Cube IDE to Implement a Sequence Where Three LEDs Blink in Various Combinations.
Here, is a step by step guide to get started with STM32 black pill and STM cube IDE to implement a sequence where three LEDs blink in various combinations. These combinations will include patterns such as 100, 010, 001, 110, and others, amounting to a total of 9 distinct combinations using HAL programming.
Supplies
- STM32 Black pill
- 3Led's
- Breadboard
- Jumper Wire
- USB type C cable
- STM 32 Cube ide
- STM 32 Cube Programmer
Setting Up STM32 Cube IDE
- Download and install STM32CubeIDE on your computer.
- Launch STM32CubeIDE and initiate a new project. a. Select "New STM32 Project" from the Quick Start menu. b. Choose your board or microcontroller (STM32F103C8) and proceed with the Next option. c. Configure project name and location, then click Finish.
Configuring the GPIO Pins and LED
- In STM32CubeIDE, navigate to the "Pinout & Configuration" tab.
- Configure three GPIO pins for controlling LEDs (e.g., GPIOA Pin 0, Pin 1, Pin 2 for Red, Green, Blue LEDs).
- Set these pins as GPIO Output and enable GPIO clock.
Code
- Navigate to the "Core" folder in the project explorer and open main.c.
- Include necessary libraries and header files.
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,0);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_6,1);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_7,1);
HAL_Delay(1000);
Final Building and Testing
- Connect your STM32 Black Pill board to your computer using a USB cable.
- Build the project by clicking on the hammer icon in the toolbar.
- Once the build is successful, click the play (debug) button to flash the code onto the board.
- Navigate to the "Core" folder in the project explorer and open main.c
- Include necessary libraries and header files.
- Generate .elf file and copy the path of that file and paste in STM32 cube programmer and the project is ready.