Micro bit Basic Programming Guide Input Function Group Special Analysis 11

Mondo Technology Updated on 2024-01-31

Start planning my 2024 micro:bit basic programming guide Input Function Group (Special Analysis)11

gpioThe concept and principle of port multiplexing

Port multiplexing refers to the process of using one pin for multiple functions. In STM32 microcontrollers, each pin has multiple application functions such as GPIO, UART, SPI, etc. By configuring the corresponding control registers, we can set the pins to different functions.

In the pin multiplexing of the STM32, each pin has a corresponding port control register (GPIOX CRH or GPIOX CRL) and a multiplexing control register (GPIOX AFIOx). The port control registers are used to configure the general function part of the pin, such as input and output mode, output speed, pull-up and pull-down parameters, and the multiplexed control register is used to configure the specific function of the pin, usually referring to other application functions other than GPIO. Since the GPIO function is usually considered the default function, there is no need to reuse the control registers to set them again.

The following figure shows how to configure the port pin function

(2) Analysis of commonly used IO port modes

Here's an induction, a summary:

1. Push-pull output: It can output high and low level, and connect digital devicesThe push-pull structure generally means that the two transistors are controlled by two complementary signals respectively, and the other is always cut off when one transistor is turned on. The high and low levels are determined by the IC's power supply.

The push-pull circuit is two triodes or MOSFETs with the same parameters, which exist in the circuit in a push-pull mode, and each is responsible for the waveform amplification task of positive and negative half-cycles. The output can either sink current into the load or draw current from the load. The push-pull output stage increases both the load capacity of the circuit and the switching speed.

Detailed understanding:

2. Open-drain output: The output terminal is equivalent to the collector of the triode. To get the high state, you need a pull-up resistor. It is suitable for current type drive, and its ability to absorb current is relatively strong (generally within 20mA).

The open-drain form of the circuit has the following characteristics:

a.The driving capability of the external circuit is used to reduce the driving power inside the IC. When the internal MOSFET of the IC is turned on, the drive current flows from the external VCC through the R pull-up resistor, and the MOSFET to GND. Only a small gate drive current is required inside the IC.

b.Generally speaking, the open-drain is used to connect devices of different levels, and the matching level is used, because when the open-drain pin is not connected to an external pull-up resistor, it can only output a low level, and if it needs to have the function of outputting a high level at the same time, it needs to be connected to the pull-up resistor, a good advantage is that the transmission level can be changed by changing the voltage of the pull-up power supply. For example, with a pull-up resistor, it can provide TTL CMOS level output, etc. (The resistance of the pull-up resistor determines the velocity along the logic level transition.) The larger the resistance, the lower the speed, and the smaller the power consumption, so the selection of the load resistor should take into account both power consumption and speed. )

c.Open-drain provides a flexible output method, but it also has the disadvantage of introducing a rising edge delay. Because the rising edge is charged to the load by an external pull-up passive resistor, the delay is small when the resistor is selected, but the power consumption is largeOn the contrary, the delay is large and the power consumption is small. Therefore, if there is a requirement for delay, it is recommended to use the falling edge output.

d.Multiple open-drain output pins can be connected to a single wire. With a pull-up resistor, an "and-logic" relationship is formed without adding any additional devices. This is also the principle used to judge the occupancy status of the bus in bus communication such as I2C and SMBUS. In fact, it can be simply understood as: when all pins are connected together, an external pull-up resistor, if there is a pin output for logic 0, which is equivalent to grounding, and the parallel circuit is "equivalent to being short-circuited by a wire", so the logic level of the external circuit is 0, and only when it is high, the result of and is logic 1.

3. Floating input: For floating input, because floating input is generally used for external key input, combined with the input part circuit on the diagram, it is understood that in the floating input state, the level state of IO is uncertain, which is completely determined by the external input, and if the pin is suspended, the level of the port is uncertain.

3) Practical application

1) Floating input in floating - floating input, can be used for key recognition, rx

2) With pull-up input IPU - IO internal pull-up resistor input.

3) With pull-down input IPD - IO internal pull-down resistor input.

4) Analog input AIN - Apply ADC analog input, or save power at low power consumption.

5) Open-drain output out od - IO output 0 is connected to GND, IO output 1, floating, and an external pull-up resistor is required to achieve high output level. When the output is 1, the state of the IO port is pulled up by the pull-up resistor, but because it is an open-drain output mode, the IO port can also be changed to a low level or unchanged by the external circuit.

6) Push-pull output out pp - IO output 0 - connected to GND, io output 1 - connected to VCC.

7) Push-pull output AF PP of multiplexing function - on-chip and off-chip peripheral functions (SCL for I2C, SDA).

8) Open-drain output AF OD of multiplexing function - on-chip and off-chip peripheral functions (TX1, MOSI, MISO.)sck.ss)

There are generally 5 ways to use a pin function, and they are configured as follows:

1) As a normal GPIO input: Configure the pin as a floating input, a weak pull-up input or a weak pull-down input as needed, and do not enable all multiplexed function modules corresponding to the pin.

2) As a normal GPIO output: Configure this pin as a push-pull output or open-drain output as needed, and do not enable all multiplexed function modules corresponding to this pin.

3) As a normal analog input: Configure the pin to analog input mode, and do not enable all the multiplexing function modules corresponding to the pin.

4) Input as built-in peripherals: Configure the pin as a floating input, a weak pull-up input or a weak pull-down input as needed, and enable a multiplexing function module corresponding to the pin.

5) As the output of the built-in peripherals: configure the pin as a multiplexed push-pull output or a multiplexed open-drain output as needed, and enable all multiplexed function modules corresponding to the pin.

Note that if there are multiple multiplexed function modules corresponding to the same pin, only one of them can be enabled, and the other modules remain unenabled.

The above is ———

Original link: Super detailed analysis of the eight working modes of STM32IO port - Zhihu.

Related Pages