This page was machine-translated and may differ from the original. View original

[Serial] ST Yuji Kawano Engineer ⑨ - GPIO, the Core of MCU Input/Output

Google 우선 소스Published2021.12.07 10:28
GPIO, the core of MCU input/output

GPIO, STM32/STM8 MCU I/O ports
Used for various applications and purposes


[Editor's Note] When people think of semiconductors, they usually think of familiar semiconductors like computer CPUs and memory. Conversely, MCUs (Micro Controller Units), the core semiconductors that power electronic devices, are widely used in virtually every electronic device we encounter, yet they remain relatively unfamiliar to the general public. Recently, MCUs have been making headlines due to the semiconductor shortage, drawing public attention. Therefore, this magazine has prepared a series of articles by Yuji Kawano, Manager at STMicroelectronics, a company specializing in MCU semiconductors, to provide an in-depth look at MCUs.

■ MCU that inputs and outputs binary signals

The simplest tasks a microcontroller (MCU) performs are outputting binary (0/1) signals through a port and reading binary signals from the port. While simple, these functions are essential and are implemented in all high-performance MCUs. This paper describes the devices and input/output ports that perform these functions.

■ IO, a component that reads binary signals

Input/output ports are generally defined as components that output binary signals through the port and read binary signals input from the port. Such ports are also called IO (or I/O) ports. The I/O ports of the STM32 and STM8 MCUs produced by STMicroelectronics (hereinafter referred to as ST) are called GPIOs (general-purpose input/output pins) because they are used for a variety of applications and purposes. The word "port" can certainly be thought of as a port where cargo is loaded and shipped. This is an apt metaphor for the role performed by the MCU, except that the "cargo" that the MCU processes is data fragments consisting of 0s and 1s.



▲Figure 1: Role of GPIO



Figure 1 illustrates one of the simplest applications for GPIO. When the push-button switch is off, a "0" (ground level) is input to port 2. When the button is pressed, the input changes to a "1" (power supply voltage level). However, if port 1 normally outputs '1', the LED will remain turned off, and if it outputs '0', the LED will turn on.

These functions are linked to the MCU program, and when the button is pressed, the LED turns on, and when the button is not pressed, it turns off.

Examples of how this port might be used in practice include replacing a push-button switch with a control circuit input signal and replacing an LED with a motor-driver IC.



▲Figure 2: GPIO structure



Next, let's examine the internal structure of GPIO. Because MCU architecture varies by manufacturer, detailed information about a specific MCU's architecture requires reading the relevant user manual. For example, let's examine the GPIO structure of the STM32.

Figure 2 shows a structural diagram of GPIO. The upper part is the input circuit, and the lower part is the output circuit. On the right are the GPIO pins through which data is input and output. Immediately following these pins are protection diodes that protect against noise and surge voltages relative to power or ground. GPIOs have pull-up/pull-down resistors, reducing the number of external resistors required. Software can connect or disconnect these pull-up/pull-down resistors within the circuit. The CMOS circuit accepts input data and passes it on to the internal circuitry. This CMOS circuit is referred to as the input buffer. In this diagram, a CMOS inverter is used as the buffer.

Data output from the MCU is transmitted through the output buffer. This buffer consists of a CMOS inverter and uses high-performance CMOS to drive circuits outside the MCU.

One type of GPIO structure is the NMOS open-drain structure, where the NMOS drain remains open, i.e., the PMOS is not connected to the NMOS.

An output buffer composed solely of NMOSs (i.e., without PMOSs) is called an NMOS open-drain. For reference, this type of drain is shown on the right side of Figure 2. This buffer requires an external pull-up resistor because it cannot output a "1" (high) signal on its own. For example, an NMOS open-drain structure is used for I2C communication ports.

Since electrical signals are actually the inputs of GPIO circuits, when you want to make a push-button circuit, you need to know which voltage represents '0' and which voltage represents '1'. In the case of digital logic circuits such as MCUs, the boundary level between the two voltage ranges representing '0' and '1' is called the threshold level. Since CMOS circuits receive signals from the internal circuits of the MCU, the threshold level is the voltage that turns on or off the PMOS/NMOS circuits that make up the CMOS.



▲Figure 3: Threshold values



Now, let's look at Figure 3(a). Let's assume that the input voltage to the GPIO is gradually increased from GND (0 V) until it reaches the power supply level, and then gradually decreased again. Initially, the GPIO interprets the input voltage as "0," but once it exceeds a certain voltage, the GPIO interprets it as "1." As mentioned earlier, this boundary voltage is called the threshold voltage. When the output voltage falls below the threshold voltage, the GPIO interprets it as "0" again.

To ensure stable operation even with noisy input signals, another type of GPIO has two threshold levels. One threshold is for transitions from '0' to '1', and the other is for transitions from '1' to '0'. GPIOs that use two thresholds are said to have Schmitt-trigger characteristics.

Next, let's look at Figure 3(b). This figure differs from Figure 3(a). The threshold for the transition from '0' to '1' is not the same as the threshold for the transition from '1' to '0'. The voltage difference between these two threshold levels is called the hysteresis voltage range.

Once a GPIO recognizes a voltage level as '1' or '0', it will not recognize any fluctuations in the input level, even if there is noise, as long as the voltage level fluctuates within the hysteresis voltage range. In other words, it is noise-resistant.

This type of GPIO is used for clock input ports for communication, reset ports, interrupt request ports, etc., and prevents noise-induced errors (including voltage fluctuations and chattering).

Different MCUs use different conditions for the input characteristics, but VIH is generally used to refer to the H-threshold, and VIL is used to refer to the L-threshold.

■ Be careful that there are environments where the output is neither '1' nor '0'.



▲Figure 4: Output characteristics




In general, VOH represents the output voltage of '1', and VOL represents the output voltage of '0'. The characteristics of the output buffer MOS affect these voltages. Let's look at Figure 4. When '1' is the output (Figure 4(a)), the PMOS is turned on, and when '0' is the output (Figure 4(b)), the NMOS is turned on. In the former case, the output voltage is slightly different from the supply voltage (Vdd) due to the voltage drop that appears across the PMOS (Vpmos in Figure 4). In the latter case, the output voltage is slightly different from the GND level (Vss) due to the voltage drop that appears across the NMOS (Vnmos in Figure 4). As a result, the output voltage is as follows. VOH = Vdd - Vpmos and VOL = Vss + Vnmos. For specific values, please refer to the manual that specifies the electrical characteristics of the relevant MCU.

It should be noted that there are circumstances where the output is neither '1' nor '0'. This condition, which occurs when both the PMOS and NMOS are off, is called a 'high impedance state', 'open state', or 'tri-state', and is denoted as 'HZ' or 'High-Z'. High impedance means that the output state has high impedance with respect to the power supply or GND. Since this output characteristic is a third state other than the two states of H and L, it is called a 'tri-state'. An 'open state' means that the output circuit is not connected to anything.
본 기사에 대한 정정·반론·추후보도 청구는 보도 청구 안내를, 그간 게재된 보도문은 정정·반론보도 모아보기를 참고해 주세요.
명세환 기자
명세환 기자