1. Input floating
2. Input pull-up
3. Input pull-down
4. Analog input
5. Open drain output
6. Push-pull output
7. Push-pull multiplexing function
8. Open drain multiplexing function
Each IO port of STM32 is controlled by 7 registers. They are: 2 32-bit port configuration registers CRL and CRH in configuration mode; 2 32-bit data registers IDR and ODR; 1 32-bit set/reset register BSRR; 1 16-bit reset register BRR; 1 32-bit latch register LCKR; Here we only introduce several commonly used registers, and we only use 4 IO port registers: CRL, CRH, IDR, ODR.
The IO port configuration table of STM32 is shown in Table 3.1.1.1:
The STM32 output mode configuration is shown in Table 3.1.1.2:
The reset value of this register is 0X4444 4444. As can be seen from the figure above, the reset value is actually to configure the port to floating input mode. From the figure above, it can also be concluded that the CRL of STM32 controls the mode of the lower 8 bits of each IO port (A~G). The bits of each IO port occupy 4 bits of CRL, the upper two bits are CNF, and the lower two bits are MODE. Here we can remember several commonly used configurations, such as 0X0 for analog input mode (for ADC), 0X3 for push-pull output mode (for output port, 50M rate), 0X8 for pull-up/pull-down input mode (for input port), and 0XB for multiplexed output (using the second function of the IO port, 50M rate).
Let's take an example. For example, we want to set the 11th bit of PORTC as pull-up input and the 12th bit as push-pull output. The code is as follows:
GPIOC->CRH&=0XFFF00FFF; //Clear the original settings of these two bits, and do not affect the settings of other bits
GPIOC->CRH|=0X00038000; //PC11 input, PC12 output
GPIOC->ODR=1<<11; //PC11 pull-up
IDR is a port input data register, which only uses the lower 16 bits. This register is a read-only register and can only be read out in 16-bit form. The description of each bit of this register is shown in the figure below:
To know the status of a certain IO port, you just need to read this register and look at the status of a certain bit. It is relatively simple to use.
ODR is a port output data register, and only the lower 16 bits are used. This register is readable and writable. The data read from this register can be used to determine the output status of the current IO port. Writing data to this register can control the output level of a certain IO port. The description of each bit of this register is shown in the figure below:
Here, we can summarize. For those who have learned AVR, we all know that the IO port of AVR is controlled by 3 registers: DDR, PORT, and PIN. Here we can make an analogy between the IO control registers of STM32 and AVR:
1.
The CRL and CRH of STM32 are equivalent to the DDR registers of AVR, which are used to control the direction of the IO port, but the CRL and CRH of STM32 are more powerful.
2.
The ODR of STM32 is equivalent to the PORT of AVR, which is used to control the output level of the IO port or the pull-up and pull-down resistors.
3.
The IDR of STM32 is equivalent to the PIN of AVR, which is used to store the current input status (high and low levels) of the IO port.
In addition, STM32 also has several registers such as BSRR, BRR, LCKR, etc. for controlling the IO port, which is not available in AVR.
Previous article:STM32 watchdog configuration
Next article:Organize the application of system clock timer--SysTick
Recommended ReadingLatest update time:2024-11-16 08:52
- Popular Resources
- Popular amplifiers
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
- Linux driver programming - ch340x driver transplantation
- Brief Discussion on the Development of Automation Instruments
- One controller is 3.3v, use TLP521-4 optocoupler to convert to 24v
- What are the advantages of digital circuits compared to analog circuits?
- GD32E230C development board button problem
- New Horizons to Pluto: Qorvo Helps Send Images from Pluto to Earth
- [GD32L233C-START Evaluation] Generation, compilation and download of RT_T project
- stm32L011F4 Under low power consumption, the current will suddenly increase
- ST60 Short-range Contactless 60GHz Millimeter Wave Connector Different Obstacle Test
- Solve the problem of BQ76930 20 series circuit driving circuit