STM8 General Purpose Input and Output (GPIO)

Publisher:静默思考Latest update time:2019-11-25 Source: eefocusKeywords:STM8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

STM8_IO port configuration table 1

STM8_IO port configuration table 2
(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)


Keywords:STM8 Reference address:STM8 General Purpose Input and Output (GPIO)

Previous article:STM8L EEPROM reading and writing principles and routines
Next article:STM8S103 tim2 capture cycle

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号