Stm32f4--gpio Basic Application and reuse

Source: Internet
Author: User

IO Basic applications

First, IO basic structure:

There are 7 sets of iofor stm32f407 , each of which is Gpioa~gpiog, each set of io has io port, there is a single io port. The basic structure of IO port is as follows:

Second, the mode of work:

STM32F4 Working mode has 8 kinds, including 4 input mode,4 output mode, respectively: input floating space, input pull-up, input pull-down, analog mode, open-drain output, open-drain multiplexing output, push-pull output, Push-pull multiplexing output.


1. Input mode:

In the input float mode, the circuit is neither pulled up nor pulled, and sent through the Schmitt trigger to the input data register at the Fed to the CPU. The input pull-up and pull-down modes are the CPUsthat are fed through the Schmitt trigger after pull-up and pull-down in the circuit, and in analog mode, the Schmitt trigger shuts down the signal directly through the analog channel to the on-chip peripherals.

2. Output mode:

In the open-drain output mode, theCPU sends input directly or indirectly to the control output data register, through the output control circuit, when the signal is 1 ,N-MOS tube is closed, so IO The level is controlled by the upper and lower circuit, when the signal is 0 , theN-MOS tube on the output is low-level, push-pull output mode, the signal is 1 ,p-mos tube conduction, N-mos Tube Cutoff, the output is high-level pull up, when the signal is 0 ,p-mos tube cutoff,n-mos tube conduction, the output is low-level down , the difference between open-drain multiplexing and push-pull multiplexing modes and open-drain and push-pull is that the source of open-drain multiplexing and push-pull multiplexing is a peripheral module on the chip.


Third, related registers

    every common Span lang= "en-US" >io ports include 4 32 bit configuration registers (gpiox_ moder , gpiox_otyper, piox_ospeedr and Gpiox_ PUPDR 2 32 bits (gpiox_idr gpiox_odr ), 1 32 position bit / Reset Register (GPIOX_BSRR 1 32 bit lock register (gpiox_lckr ) and 2 32 bit Multiplexing Feature selection register (gpiox_afrl ). It is described below.

    1 , working mode configuration: 1 , Port mode (gpiox_moder ): The mode used to configure the port is input, output, multiplexing, and analog mode. 2 , Port type (gpiox_otyper ): The mode used to configure the register is output push-pull or output open-drain. 3 , Port speed (piox_ospeedr ): The information transfer rate used to configure the port. 4 , Port pull-down (gpiox_pupdr ): Used to configure the port without pull, pull, drop-down, and retention modes.

    2 , level configuration: 1, input data (GPIOX_IDR ): Use its low 16 bits, respectively, corresponding to the group io port level state. 2 , output data (gpiox_odr ): Features similar to input data registers. 3 , set and reset (gpiox_bsrr ): With the first two different is the set and reset register used bit, low 16 is set to 1 , which is used to place 1 corresponding bit, high When the span lang= "en-us" >16 bit is set to 1 , it is used to place 0 corresponding bit, while the low 16 bits and high 16 bits are set to 0 without affecting the original value.

3. Multiplexing function Configuration: follow the instructions below.


IO Multiplexing

First, reuse background:

Due to the limited IO port, in order to save IO resources, and in order to better coordinate the work between io , it is necessary to give the IO Port A different function at the appropriate time, an io The mouth can take on different tasks at different times, which is the multiplexing function of IO .

Second, the principle of re-use:

Each IO port is followed by a selector that, after the configuration of the corresponding registers (gpiox_afrh and gpiox_afrl), can be used to perform different functions, and this register is gpiox_afrh and gpiox_afrl.

Three, register configuration:

Each set of IO ports has a AFRL and a afrh register, each of which is a register of 4 bits, each of which features an IO port, The corresponding GPIOX_AFRL is used to configure the 0-7 io port,gpiox_afrh is used to configure the 8-15 io mouth. Each 4 -bit configuration of an IO port, the relevant value of 4 -bit data will have corresponding function. In this way, the relevant configuration is done.


Review:

These related configuration procedures will use the corresponding functions and corresponding variables, skilled use of the relevant functions, while the function of the functions of understanding before the application of more handy, but also can write some of their own related functions to operate, of course, can also directly manipulate the relevant registers.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Stm32f4--gpio Basic Application and reuse

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.