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 Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

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

  • CMOS ring oscillator
  • Self-powered Current Transducer Buyer's Guide
  • Question on options of set_clock_group
  • Egs002
  • BA4116 reference resistance

RSS Electro-Tech-Online.com Discussions

  • Fixing board, Easy question HEX SCHMITT
  • Can I make two inputs from one??
  • Display TFT ST7789 (OshonSoft Basic).
  • Home Smoke detectors are all Beeping Batteries are not dead.???
  • The Analog Gods Hate Me

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • How to monitor temperature and humidity on a TFT display with graphics
  • Tria modules integrate edge AI processing with multi-core processors
  • pSemi introduces RF switch with 52 dBm PMAX,PEAK and 90-dBm IIP3 linearity
  • XP Power launches 1.3 kW power supply with 58.9 W/cmÂł density
  • How to enable Wi-Fi provisioning in ESP32-based IoT products

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