The GPIO is in input mode, and the relevant configuration for the drop-down input and pull-up input is shown in the following figure. It is important to note that the drop-down input and the pull-up input are distinguished by the port output register GPIOX_ODR. As a result, when the pull-up/drop-down input is configured, the operation on the input to the GPIO is still configured for the register ODR associated with the output.
The above considerations appear when the actual code is written: (1) Library functions
Gpio_initstructure.gpio_pin = gpio_pin_0; PA0
gpio_initstructure.gpio_mode = GPIO_MODE_IPD;//pa0 drop-down input
gpio_init (Gpioa, &gpio_initstructure);
Gpio_resetbits (GPIOA,GPIO_PIN_0); PA0 drop-off odr=0<strong>
</strong>
It is hereby stated that although the pull-up input mode Gpio_mode_ipu and the drop-down input mode GPIO_MODE_IPD are distinguished in Gpio_mode, the ODR registers are still required to be set when the Gpio initializes the configuration, as shown in the above Gpio_ Resetbits (gpioa,gpio_pin_0); operation.
(2) Register
gpioa->crl&=0xfffffff0; PA0 set
gpioa->crl|=0x00000008; before purging PA0 input
gpioa->odr|=0<<0; PA0 drop-down <strong>
</strong>
In addition, the GPIO is in input mode and does not need to be set for MODE1 and MODE0 (default is 00 after initialization)
Output mode bit (configured in output mode only, not required in input mode)