Blink On- Board LED Using HAL Programming.
by khushpreet in Circuits > Microcontrollers
108 Views, 0 Favorites, 0 Comments
Blink On- Board LED 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 displays. It will help us become experts in this area.
In this detailed guide, we explore how to blink on-board LED of STM32 Black Pill microcontroller, 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 )
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 PC13 pin, and click “GPIO_Output”. This pin is the pin connected to a user-controlled LED on the black pill. If you look on the black pill, you can see the LED we want to control, and see it has C13 next to it. We can set other pins to use more of the black pill board, but for now, that’s all we need to do
Clock Configuration
Set up all the clock configurations and resolve clock issues
Code
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 onboard LED (connected to pin 13) as an output. The while loop toggles the LED on and off every second.
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. Here we can add our code to turn the PC13 pin on and off.
while (1)
{
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 0);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, 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!
LED on-board is glowing!