Each port is assigned registers: output register (ODR), input register (IDR), data direction register (DDR), control register 1 (CR1) and control register 2 (CR2). The latter three register groups can be configured into 8 GPIO modes. Whether an I/O port works in input or output depends on the state of the data direction register of the port. By setting 0/1 in ODR and IDR, the data input and output can be turned on and off.
GPIO main functions
Selectable input mode: floating input and input with pull-up
Selectable output modes: push-pull and open-drain
Data input and output use separate registers
External interrupts can be enabled and disabled individually
Output slew rate control to reduce EMC noise
I/O function multiplexing of on-chip peripherals
When used as analog input, the input Schmitt trigger can be turned off to reduce power consumption
Supports read-modify-write while data output is latched
Input compatible with 5V voltage
The I/O port operating voltage range is 1.6 V to VDDIOmax
I/O configuration and use
Each port has an output data register (ODR), a pin input register (IDR) and a data direction register (DDR) that are always associated with it.
Control Register 1 (CR1) and Control Register 2 (CR2) are used to configure the input/output. Any I/O pin can be configured by programming the corresponding bits in the DDR, ODR, CR1 and CR2 registers.
Bit n in the register corresponds to pin n of the port. The various configurations are summarized in Table 18.
(Table 18: IO Port Allocation Table)
Note: A diode connected to VDD is not effective in actual open drain state on the pin, only a local protection device between the pin and VOL is effective.
Unused I/O pins must be connected to a fixed level, either pulled up or pulled down.
Input Mode
Clearing the DDRx bit to 0 selects input mode. In this mode, reading the IDR register bit will return the level value on the corresponding I/O pin.
As shown in Table 18, theoretically, STM8 can get four different input modes through software configuration: floating input without interrupt, floating input with interrupt, pull-up input without interrupt and pull-up input with interrupt. However, in actual situations, not all ports have external interrupt capability and pull-up. Users should refer to the data sheet for the actual hardware performance description of each pin for more details.
Output Mode
Setting the DDRx bit to 1 selects the output mode. In this mode, writing data to the ODR register bit will output the corresponding digital value to the I/O port through the latch. Reading the IDR bit will return the corresponding I/O pin level value. Different output modes can be obtained by software configuration of the CR1 and CR2 registers: pull-up output, open-drain output.
1. Pull-up input: Pull-up means pulling the potential up, such as pulling it to Vcc. Pull-up means embedding an uncertain signal at a high level through a resistor! The resistor also acts as a current limiter! Weak and strong are just different in the resistance value of the pull-up resistor, and there is no strict distinction.
2. Pull-down input: pull the voltage down to GND. Similar to the pull-up principle.
3. Floating input: Floating means that the input pin of the logic device is neither connected to a high level nor to a low level. Due to the internal structure of the logic device, when its input pin is suspended, it is equivalent to the pin being connected to a high level. In general, it is not recommended to leave the pin suspended in practice, as it is susceptible to interference. In layman's terms, it means leaving the pin unconnected and floating.
4. Analog input: Analog input refers to the traditional input method. Digital input is the input PCM digital signal, that is, the binary digital signal of 0, 1, which is converted into an analog signal through digital-to-analog conversion, and enters the power amplifier after pre-amplification. The power amplifier is still analog.
5. Push-pull output: can output high and low levels, connect digital devices; push-pull structure generally refers to two transistors being controlled by two complementary signals, always one transistor is turned on while the other is turned off. The high and low levels are determined by the power supply of the IC.
6. Open-drain output: The output terminal is equivalent to the collector of the transistor. A pull-up resistor is required to obtain a high-level state. It is suitable for current-type driving and has a relatively strong ability to absorb current (generally within 20ma).
7. Multiplexed open-drain output and multiplexed push-pull output: This can be understood as the configuration when the GPIO port is used as a second function (that is, not used as a general IO port).
Select IO mode in STM32. The following is a summary of references on the Internet.
(1) Floating input_IN_FLOATING - floating input, can be used for KEY recognition, RX
(2) Pull-up input_IPU - IO internal pull-up resistor input
(3) Pull-down input_IPD - IO internal pull-down resistor input
(4) Analog input_AIN - ADC analog input, or power saving under low power consumption
(5) Open drain output_OUT_OD - IO output 0 connected to GND, IO output 1, floating, requires an external pull-up resistor to achieve high output level. When the output is 1, the state of the IO port is pulled high 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 an external circuit. Can read IO input level changes to realize C51 IO bidirectional function
(6) Push-pull output _OUT_PP - IO output 0- connected to GND, IO output 1 - connected to VCC, read input value is unknown
(7) Multiplexed function push-pull output _AF_PP - on-chip external function (I2C SCL, SDA) (8) Multiplexed function open-drain output _AF_OD - on-chip external function (TX1, MOSI, MISO.SCK.SS)
Previous article:STM8L EEPROM reading and writing principles and routines
Next article:STM8S103 tim2 capture cycle
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- dsp DM642 uses timer to light up LED source program
- [2022 Digi-Key Innovation Design Competition] I am just an image porter
- Nengdian Electronics Capacitive Liquid Level Sensor D1CS-D54 Review
- [Zhongke Bluexun AB32VG1 RISC-V board "meets" RTT] GPIO simulation realizes full-color LED lights
- Solution | Application of Feiling FETMX8MP-C core board in AGV car
- What will happen if you connect the input and output of the power bank?
- AD package library
- Share a reference implementation of path planning, the key is that there are animated pictures!
- TMS320C6678 chip TI original board development
- How to configure practical Euler angles for sensortile box?