Detailed analysis of the working mode of the microcontroller IO port
[Copy link]
The working modes of the microcontroller I/O port are basically divided into the following categories:
1. Quasi-bidirectional IO port configuration (weak pull-up)
summary:
Strong current sinking capability, weak current sourcing capability
Before reading the external status, latch "1" (disconnect the pull-down transistor)
The principle of reading the IO port status is either high or low. It can only accurately identify external low-level signals, and cannot distinguish between floating and true high levels.
When used as input, the input impedance is not high resistance, and the external low level may be misread as a high level (for example, the pull-up resistor is 10K, the external resistor is 100K, IO=5*100/110=4.54V)
For reference, please refer to:
When the quasi-bidirectional port is used as input, a button can be connected to ground, as shown in Figure 1. Of course, R1 can be removed and the button can be connected directly. When the button is closed, the port is pulled to a low level. When the button is released, the port is pulled to a high level by the internal "very weak pull-up" transistor.
When the port is used as output, the external LED connected to the ground should not be controlled as shown in Figure 2, because the driving ability of the port is very weak (weak current pulling ability), and the LED can only emit very weak light. If you want to drive the LED, you should use the method shown in Figure 3. In this way, the quasi-bidirectional port can absorb 20mA of current (strong current sinking ability) when the output is low, so it can drive the LED. The method shown in Figure 4 is also acceptable, but when the LED does not emit light, the port must absorb a large current.
2. Push-pull output configuration
summary:
Can truly output high and low levels, with strong driving capability (strong current sinking and current sourcing capabilities)
If two push-pull output structures are connected together, one outputs a high level, that is, the upper MOS is turned on and the lower MOS is closed; at the same time, the other outputs a low level, that is, the upper MOS is closed and the lower MOS is turned on. The current will flow directly from the VCC of the first pin through the upper MOS and then through the lower MOS of the second pin to GND. The resistance in the entire path is very small, and a short circuit will occur, which may cause damage to the port. This is why push-pull output cannot achieve "wired AND".
The push-pull output can drive the LED light by pulling current in the manner shown in Figure 2.
3. Open-drain output configuration
summary:
Output high level through external pull-up resistor
If there is an external pull-up, it can be used as an input IO to read the external state (same as quasi-bidirectional IO, latch "1" first)
External pull-up power supply for level shifting and compatibility with external devices
4. High impedance input
summary:
The circuit cannot flow in or out, and can only be used as input data
|