STM32 Entry Series-GPIO Working Mode and LED Circuit Principle[Copy link]
GPIO working mode Due to the internal structural relationship of GPIO, GPIO can be configured into the following modes. Input mode In input mode, the Schmitt trigger is turned on and the output is disabled. The I/O status can be read through the input data register GPIOx_IDR. The input mode can be configured as analog, pull-up, pull-down and floating mode. Pull-up and pull-down inputs are easy to understand, and the default level is determined by pull-up or pull-down. The level of floating input is uncertain and is completely determined by external input. This mode can generally be used when connecting buttons. Analog input is used for ADC acquisition. Output mode (push-pull/open drain) In the output mode, the dual MOS tube works in push-pull mode, and the output data register GPIOx_ODR can control the high and low levels of the I/O output. In the open drain mode, only the N-MOS tube works, and the output data register can control the I/O output high impedance or low level. The output speed is configurable, with options of 2, 25, and 50MHz. For more information on embedded IoT smart hardware, please add Penguin. The output speed here is the highest switching frequency of the high and low levels supported by the I/O. The higher the supported frequency, the greater the power consumption. If the power consumption requirement is not strict, just set the speed to the maximum. In output mode, the Schmitt trigger is open, that is, the input is available, and the actual state of the I/O can be read through the input data register GPIOx_IDR. Multiplexing function (push-pull/open drain) In multiplexing function mode, the output is enabled, the output speed is configurable, and it can work in open drain and push-pull mode, but the output signal comes from other peripherals, and the output data register GPIOx_ODR is invalid; the input is available, and the actual state of the I/O can be obtained through the input data register, but generally the data signal is directly obtained using the peripheral register. Analog input and output (no effect on pull-up and pull-down) In analog input and output mode, the dual MOS tube structure is turned off, the Schmitt trigger is disabled, and the pull-up and pull-down are also disabled. Other peripherals use analog channels for input and output. By writing different parameters to the GPIO register, the application mode of GPIO can be changed. I would like to emphasize that when you want to understand the specific registers, you must refer to the register description of the corresponding peripheral in the "STM32F1xx Reference Manual". In the GPIO peripheral, the working mode and output speed of GPIO can be configured by setting the "port configuration registers GPIOx_CRL and GPIOx_CRH". CRH controls the high eight bits of the port, and CRL controls the low eight bits of the port. LED circuit of STM32F1xx The LED circuit diagram on the development board is shown in the figure below. The same network label means they are connected together, so the cathode of D1-D8 LEDs is connected to the PC0-PC7 pins of STM32. If you want to light up the D1 indicator, you only need to control the PC0 pin to output a low level. If you want to turn off the D1 indicator, you only need to control the PC0 pin to output a high level. The control method for other LEDs is the same. If you are using other boards and the pins and polarities of the LEDs are different, you only need to modify the corresponding GPIO pins and output level states in the program. The principle is the same. To light up the D1 LED, let the PC0 pin of STM32 output a low level. This content is originally created by EEWORLD forum user jingcheng. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source