The schematic diagram is as follows (taking the LED light connected to the PH10 pin as an example)
We only need to give the PH10 pin a low level, then the LED will light up.
The internal GPIO schematic is shown in the figure. The red arrow indicates the GPIO output direction. As long as data is written to the set/reset register, the data will be transferred to the output data register (or the output data register can be directly assigned a value), and then the high and low levels will be output through the push-pull output circuit.
First configure the registers related to the PH10 pin (register map)
By referring to the reference manual of stm43f4, the relevant register mapping is as follows (the function of each register will be discussed below)
Next, configure the relevant registers in the following order
1. GPIO mode
First, we configure the PH10 pin connected to the LED light to output mode, that is, configure the GPIO MODER register, which contains pins 0-15, and each pin occupies 2 register bits. When these two register bits are set to "01", it is the GPIO output mode.
2. Output Type
GPIO output has two types: push-pull and open-drain. We know that the open-drain type cannot directly output high level. To output high level, a pull-up resistor must be connected to the chip externally, which does not conform to our hardware design, so we directly use the push-pull mode. Configure the OTYPER10 register bit in the OTYPER register. When this bit is set to 0, the PH10 pin is in push-pull mode.
3. Output speed
The output speed of the GPIO pin is the highest frequency that the pin supports high and low level switching, which can be set at will in this experiment. Here we configure the register bit OSPEEDR10 in the OSPEEDR register to control the output speed of PH10.
4. Pull-up/pull-down mode
When the GPIO pin is used for input, the pull-up/pull-down mode of the pin can control the default state of the pin. But now our GPIO pin is used for output, and the pin is affected by the ODR register. The default value of the ODR register corresponding to the pin bit is 0 after initialization, and the pin outputs a low level, so at this time, we configure the pull-up/pull-down mode will not affect the pin level state. However, since the pull-up here can slightly increase the current output capability, we configure it to the pull-up mode, that is, configure the PUPDR10 bit of the PUPDR register and set it to the binary value "01".
5. Control pin output level
In output mode, the level state of the pin can be controlled by writing parameters to the BSRR register or ODR register.
6. Enable peripheral clock
After setting the GPIO pins and controlling the level output, you may think that you can finally light up the LED, but there is actually one last step left.
In the peripheral chapter of "STM32 Chip Architecture", it is mentioned that STM32 has many peripherals. In order to reduce power consumption, each peripheral corresponds to a clock. These clocks are turned off when the chip is just powered on. If you want the peripheral to work, you must turn on the corresponding clock.
The clocks of all peripherals of STM32 are managed by a special peripheral called RCC (reset and clockcontrol), which is described in Chapter 6 of the STM32 Chinese Reference Manual. All GPIOs are mounted on the AHB1 bus, so their clocks are controlled by the AHB1 peripheral clock enable register (RCC_AHB1ENR), where the clock of the GPIOH port is enabled by writing 1 to bit 7 of the register, turning on the GPIOH port clock.
The specific code implementation is as follows
Previous article:How to create a new stm32 firmware library project
Next article:Keil5 compiles successfully but there is a red cross
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- STM32 boot mode configuration and application
- The number series problem from "Bible Code" and the python solution
- Live broadcast at 10:30 this morning [Microchip Security Solutions | Wi-Fi Security for Enterprises]
- TI's board has arrived
- Motor stroboscope test
- [Help] Dear electronic engineers, what did you mention when you first went back to the girl's house?
- Popular Science: What is LPWA?
- EEWORLD University Hall----Intel FPGA 2019 Engineer Application Video
- Which is better, UHF wireless microphone or 2.4g wireless microphone?
- Pingtouge RISC-V Development Board--STEP1--Impression