Three External LED's Blinking Using HAL Programming
by khushpreet in Circuits > LEDs
108 Views, 2 Favorites, 0 Comments
Three External LED's Blinking Using HAL Programming
" Welcome to a place where everything fits together perfectly and is carefully engineered. Every tiny dot on the screen has a story to tell and every line of computer instructions brings our hardware to life. " Today, we start learning about how to connect a STM32 Black Pill with STM32CubeIDE to control LED's. It will help us become experts in this area.
In this detailed guide, we explore how to blink external LED using STM32 Black Pill microcontroller in HAL Programming, explaining everything in a clear and easy-to-understand way. Whether you are an experienced developer looking to learn new things or just someone interested in learning about embedded systems, this blog is designed to help and motivate you.
We use STM32CubeIDE to help us work creatively and professionally with hardware and software. Together, we'll use this special computer setup to create beautiful stories from data.
Get ready to discover all the amazing things your STM32 Black Pill can do as we learn and explore together. Let's go beyond limits, combine new ideas with old ones, and create new ways to control displays. The canvas is empty, we have all the tools we need; it's time to create something amazing that connects and works well.
Come with us as we start this journey of discovering new things. Together, we will figure out how embedded systems work and understand what is going on inside them. Welcome to a place where creativity meets smart ideas, where every computer code creates the future, and where the adventure itself is just as exciting as reaching the goal.
Supplies
- STM 32( Black Pill )
- LED's
- Breadboard
- Jumper wires
Downloading
You will need a black pill board and STM cube IDE for this project. If you don't have the IDE yet, you can get it from the STMicroelectronics website. After you install the IDE, you will need to set up your project.
Creating New Project
In the cube IDE program, go to "File" and then choose "New Project. " Pick "STM32F401CCU6" from the list and click "Next. "
Pin Configuration
Once that’s done, it will open up the pinout and configuration page. There it’ll display the physical shape of the MCU, and the pins and pin names. This is where you can set individual pins to different default values, and the IDE will use this info to auto-generate setup code. In our case, we want to just left-click the PA5, PA6, PA7 pins, and click “GPIO_Output”. These pins are the pins connected to the LED's
Clock Configuration
Set up all the clock configurations and resolve clock issues.
Code Writing
Now that your project is set up, it's time to write your code! Open the "main.c" file and enter the following code:
This code initializes the HAL library, enables the clock for GPIOC, and sets up the LED's (connected to pin A5,A6,A7) as an output. The while loop toggles the LED
To have the IDE generate code, click the save icon, or hit ctrl+s to save the configuration. It will ask if you want to generate code, and then ask if you want to open the code perspective. Click yes to both.
Now the main.c file will be open in one of the tabs. Select it.
Scroll down to the while(1) section.
while (1)
{
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);
}
Now that your code is written, it's time to build and run your project!
Creating Hex File
Click on file>properties>hex file and create a hex file
Implementation of Hex File
Open hex file in cube programmer and execute it using STM 32
Congrats!
External LED's are glowing!