HGP's study notes on in-depth learning to operate STM32LED with registers

/* @filename

  • @version1.0
  • @date 2021 2.20 14:24
  • @brief This example uses the method of manipulating registers to control the STM32's GPIO. The development board used is NECLEO_F103RB, and the PA5 is controlled to output a high level to make the LED bright. I hope I can help you reading the article O(∩_∩)O
  • @author: HGP
    /
    /

    GPIOA_CRL 0x4001 0800
    GPIOA_CRH 0x4001 0804
    GPIOA_IDR 0x4001 0808
    GPIOA_ODR 0x4001 080c
    GPIOA_BSRR 0x4001 0810
    GPIOA_BRR 0x4001 0814

Write 16
(unsigned int ) 0x3333 3333 =16 to an address in the memory

* /
#Include "stm32f10x.h"
#define GPIOA_CRL (unsigned int ) 0x40010800
#define GPIOA_CRH (unsigned int ) 0x40010804
#define GPIOA_IDR (unsigned int ) 0x40010808
#define GPIOA_ODR (unsigned int ) 0x4001080c
#define GPIOA_BSRR (unsigned int ) 0x40010810
# define GPIOA_BRR (unsigned int )0x40010814
#define RCC_GPIOA (unsigned int )0x40021018
//Configure the parameters of the PA5 pin through the data sheet

int main(void)
{

RCC_GPIOA |= (1<<2);
GPIOA_CRL |= (1<<20);
GPIOA_ODR |= (1<<5);

while(1);
}
void SystemInit()//The SystemInit function here is to prevent the program from reporting errors
{ } /*Class notes: 1. Basic idea: control the status of GPIO through the address of the register The general status register of GPIO has GPIO_CRL , GPIO_CRH, GPIO_ODR, GPIO_IDR, etc. In addition to the configuration APB2 enable register APB2ENR, because the IO port peripherals are hung on APB2. Operation to write 0 to a bit: GPIO_CRH &= ~(1 "x) Operation to write 1: GPIO_CRH |= (1 "x) x is the specific number of bits you want to move







2 The clock block diagram is very important. If you want to turn on a peripheral, you need to turn on the peripheral clock and configure its speed in advance. You can see in the clock diagram that the
systick system clock is HSI 8MHz by default. If you want to configure to 72Mhz or other, you need to configure HSE, LSE, LSI, etc.
The key to configure the clock is to have two registers, one is the frequency divider register of the clock, and the other is the register that selects the clock line.
The clock speed and system clock of the desired peripheral can be obtained through configuration.
*/
© 2021 GitHub, Inc.
Terms of Service
Privacy
Security
Status
Docs
Contact GitHub
Price
API
Training
Blog
About

Guess you like

Origin blog.csdn.net/hhhjb2/article/details/114093074