Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

Led Bar array with stm32f103 microcontroller

By EG Projects April 17, 2019

Getting started with microcontroller and leds is a basic project from where newbies start their learning of new microcontrollers. After on they start to find the different features it offers and what are its advantage over the other microcontrollers. We are gone through Getting started with stm32f103 microcontroller and now its time to learn about its other features. Unlike other 8 bit microcontrollers stm32f103 is a 32 bit microcontroller offering greater speed with greater Input/Output features. Its ports are 16-bit wide. For this tutorial i decide to work with its ports. This simple tutorial is about controlling led bar array lights with stm32f103 microcontroller. For this project is used a pre-assembled stm32 board. Particular microcontroller on board is stm32f103C8T6. Stm32cubeMx is used to initialize the microcontroller ports, pins and registers etc. Keil uvision 5 is used with HAL libraries for code building and compiling.  
Stm32f103 has 3 input/output ports. Its Port-A is 16-bit wide(From now own we will only discuss port-a). I decided to connect an 8-bit led array bar to this port and see how to manipulate the port in code. Working and understanding HAL libraries is tough and time consuming. Finally i was able to manipulate the port and i am going to present the code to newbies in this tutorial.
Led bar with stm32f103 microcontroller

Led bar with stm32f103 microcontroller

Project circuit diagram is given above. I used Port-A first 8 pins. The rest 8 i left because in the above board they are not fully exposed. Some pins are not present on board, may be due to the small size of board its impossible to expose all the pins out. One can see pin#13 and 14 of port-a are not exposed on the above board. Anyhow i connected the led bar anode side with the port-a pins of stm32 microcontroller. Cathode side is connected to ground with 220 ohm resistors. Please make sure if you are going to build the above circuit first identify the polarity of the led bar then insert it in the circuit. 
For saving microcontroller power one can connect the anode side to led array with external power or 3.3 volt output of stm32 and cathode with the stm32 pins with resistance in series. This will be the best practice. I checked the above circuit configuration it worked but it will not be advised to build the same circuit if you are also utilizing other features of stm32 microcontroller.
Coming to the code portion. The main part in code is writing to the ports. The statement

GPIOA->ODR = 0x0001;

is writing to port-a. In the above statement ODR is a 16-bit register used to write to pins on individual ports. This register is assessed with the port name. 0x0001 is a hexadecimal command. If we translate it in to binary it becomes 0000000000000001. Writing this binary value to port-a means. Pin#1 of port-a becomes high and rest of the pins remain low OR in other words first led will switch on and the rest remain off. 0x0001 is followed by 0x0003, 0x0007 and so on. All these commands are switching on leds one by one. At the end 0x0000 switches off all the leds. A quarter second delay is inserted between each command to visibly see the leds turning on one by one.
One second delay after each successive loop execution of led array is to give controller some rest. Though its not necessary to give delay here. Since microcontrollers are designed for high frequency output I just inserted it to see it by naked eye that the system is properly working and according to our our logic.  I used ST-Link v2 to upload code to microcontroller.
If you are unable to understand how ODR register is accessed and used? Where is its documentation? What about other ways to access the pins of stm32 microconntroller. Then take a small tutorial it will clear all the above answers. Link is below

Accessing stm32 ports using Hal Libraries with keil IDE

Download the project code. Stm32cubemx configuration and keil uvision 5 files are included in the folder. If you have any questions and queries please write them below in the comments section.
Code/File


Filed Under: Microcontroller Projects, STM32

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • High Side current sensing
  • How to simulate power electronics converter in PSpice?
  • Voltage mode pushpull is a nonsense SMPS?
  • Layout IRN reduction in Comparator

RSS Electro-Tech-Online.com Discussions

  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe