STM32 LED Blink example with explanation - Register level programming
Development board used : Nucleo - STM32F303RE
1. Firmware - Led blink using register programming.
Using PORT A PIN 5 ( Nucleo built-in LED is connected to this pin)
Steps:
a) Enable the port PIN as output pin
To Enable a port pin as output, set corresponding GPIOx_MODER register
Here in our case GPIOA_MODER is the register for PORT A
For each port pin, there are 2 bits reserved in this register
So for pin 5, the bits are 10,11
To set pin 5 as output pin, set 10th bit as 1 (refer the below details for register bits)
it can be done with below code
GPIOA->MODER |= 1<<10;
b) Set pin HIGH or LOW
To change the state of GPIO pin, we need to update GPIOx_BSRR register.
To set PORTA 5th pin to HIGH , set 5th bit of GPIOA_BSRR
To make the port A 5th pin LOW , set 21st bit of GPIOA_BSRR (Refere above register details)
GPIOA->BSRR |= 1<<5; <--------- Make Port A 5th pin HIGH
GPIOA->BSRR |= 1<<21; <--------- Make PORT A 5th pin LOW.
Comments