GPIO STM32 learning Configuration

A role .GPIO
1 0/1 input and output ports as the output digital signal
0 0 ~ 1.5V 1 2.5 ~ 5V TTL level
STM32 in - 0 3.3 ± 0.3V ± 0.1V. 1
2. The LED drive external circuitry , a buzzer, etc.
3. I / O port analog communication protocol the IIC
4. analog PWM wave by changing the duty cycle to achieve
two .STM32F407ZGT6 chip GPIO port number and naming
1.114 I / O ports, each I / O port has the general function of different multiplexing function
2. name pin port + + No port number
port number: ABCDEFGH a ~ G in the 16 pins per port (0 ~ 15), H only two pins (1,2)
of the five pins PA5 a port Example
III. GPIO port how
supplied through clock bus AHB1 communication with the GPIO register operator interface ----
four GPIO registers in .STM32F407ZTG6
1 register: the role of a storage space (8/16/32 bit), having a RAM having a characteristic (power-down loss of data, read and write speed), and each has its own unique position.
2. How register operation
by operating a pointer operation, for example, we want a register address 0x4000 0x4000 need only operate (assignment, subtraction, bit operation) we need by * (unsigned int *)
3. Characteristics register
read / write, read-only, write-only, read / clear, read / set, switching reserved (reserved), etc.
Data (DR) registers: receiving data stored / transmitted, generally accepted by =
configuration (Control CR) Register: configuration-related operating mode, typically used for clearing or & = ~ | = ^ = inverting a set
state ( SR) register: the state in which the peripheral, generally with 1 & reading operation
mode of the 4.GPIO
pull: 1. 2. pull high driving capability enhancement circuit
dropdown: low 1 2 pull enhanced circuit driving capability
input: four kinds of
floating inputs: the input is digital, it does not have the pull-down driving capability of the input - identification keys
pull input: the input is a digital, having an input pull-up driving capability of
pull-down input : the digital input, an input pull-down driving capability of
the analog inputs: the input is analog - digital conversion ADC
outputs: four kinds
General: function IO
multiplex: in addition to the IO functions, such as serial ports, timers,
open drain output: output 0 only (1 wants to output, pull-up resistors required) - bus communication
push-pull outputs: both output 0, output 1 can
5. by configuring procedure (LED, for example)
1. View schematics, find the corresponding led IO port

 

In pf6 an example, when the output pin is 0 led to the light.

 

 

 Here is a common feature PF6 io port function


2. General view of the IO port function is used as the IO port
3. Open clock corresponding to the GPIO port
4. The configuration mode of operation

 

A, B, C, D, E, F, G, H, I are AHB1 bus clock, so to open the clock in the figure when we operate the GPIO port, simply by setting the appropriate bit manipulation to a specific operating position

RCC-> AHB1ENR | = (1 << 0); this is the left to GPIOA 0 is set to 1.

接下来配置GPIOF的工作模式,以第6位为例

因为时通用功能,所以复用暂时不看以后会提到

led的工作模式位通用推挽输出,无上下拉,快速模式(可自己选择)

 

若要将pf6配置为通用,要在第12,13位中写入01操作如下:

//pf6 通用推挽输出
GPIOF->MODER &=~ (3<<12); //清零
GPIOF->MODER |= (1<<12); //通用输出模式
GPIOF->OTYPER &=~ (1<<6); //输出推挽
GPIOF->OSPEEDR &=~ (3<<12); //速度清零
GPIOF->OSPEEDR |= (2<<12); //快速
GPIOF->ODR |= (1<<6); //led灭

 这里因为GPIOF->ODR的复位值为0x0000 0000,而根据 原理图当该引脚输出0时led亮,所以在初始化中需要将该位置1。

 

Guess you like

Origin www.cnblogs.com/whpl22-Blog/p/11266404.html