STM32 Black Pill | Using HAL Programming to Use I2C LCD
by Anjandeep Singh in Circuits > Microcontrollers
175 Views, 1 Favorites, 0 Comments
STM32 Black Pill | Using HAL Programming to Use I2C LCD
In this tutorial, we'll use an STM32 Black Pill to program an I²C LCD on STM32CubeIDE using HAL programming.
Supplies
Hardware:
- STM32 Black Pill
- 16*2 I²C LCD
- Laptop or desktop
- USB-C cable
- Few jumper wires
Software:
- STM32CubeIDE
- STM32CubeProgrammer
Project Creation
- Create a new STM32 project from File > New > STM32 Project
- Select the appropriate board.
Pinout Selection
- Go to Connectivity > I2C1 and enable it. This will set SDA to pin 43 and SCL to pin 42.\
- Go to System Core > RCC > HSE > Crystal/Ceramic Resonator.
Clock Configuration
- Configure your board's clock.
- Save using Ctrl + S.
Writing the Program
- Go to the project file in project explorer, then Core > Src > main.c.
- Inside the function int main(void) write the following program:
HD44780_Init(2);
HD44780_Clear();
HD44780_SetCursor(0,0);
HD44780_PrintStr("Hi from Anjan");
HD44780_SetCursor(0,1);
HD44780_PrintStr("Singh");
HAL_Delay(2000);
Note: The code may vary according to your micrcontroller.
- Save the file and debug.
STM32CubeProgrammer
- We will bootload STM using USB, this tutorial does not use ST-Link.
- Next, press on "Open file" and select the .elf file from the project folder.
- Press on "Download".
- Go to "Erasing and Programming" from the menu in the left.
- Go to file path and select the .elf file and press "Start automatic mode".
- Once compiled, disconnect and reconnect the STM board.
Result
You should see the preferred result.
Thank you.