STM8 Beginner to Proficient 1

Source: Internet
Author: User

GPIO Introduction
Gpio is used for the transmission of data by single-chip microcomputer and external devices.
When the MCU Gpio is set to output, the MCU can output arbitrary data to gpio, and when the Gpio is set to the input microcontroller can read other devices and transmit to gpio data.

STM8 microcontroller each port has 8 feet, each pin, can be independently programmed for digital input or digital output, some IO port also has analog input, external interrupt, on-chip peripherals and other functions.

The functions of Stm8gpio are summarized as follows.

The individual bits of the port can be set individually,

Input mode can be selected, floating input, pull-up input
Output mode can be selected, push-pull output, open-drain output;
The output data input data has a separate register.

External interrupts can be enabled individually, or closed.

Output frequency can be set to reduce EMC

Features a second function on the on-chip peripherals.

As an analog input mode, the Schmitt trigger can be switched off to reduce power dissipation.

IO port operating voltage is 1.6 to 5v

The floating input and the pull-up input are gpio as the input two ways, the floating input is the GPIO pin level state is uncertain , susceptible to external level interference;

The input is the IO port is only high or low two kinds of states
General IO port do interrupt input to be set as pull-up input, do ad time set as floating input

The GPIO output of the microcontroller is usually formed by the current we call the pull current.
The output is a low electrical current, which we call the current sink.
The push-pull output mode is capable of independently outputting high and low levels and is suitable for driving digital devices.
Open-Drain can stabilize the output low level, can withstand large sink current, but the open-drain output can not output high level, need to external resistor to output high level, output high level, only the external pull-up level is determined, this method is suitable for the current-type drive.
Register
1-Port output data register when the PX_ODR port is set to output mode, the value written to this register is added to the corresponding pin via the chip internal latch, which reads this register to return the previously stored value.
2 port X Input Register PX_IDR tube port in input mode or output mode, you can read the register to get the level of the pin; return 0 for the corresponding tube
The foot is a logic low, and returning 1 represents the corresponding PIN as a logical high level. This register is read-only.
3 Port X Data Direction Register PX_DDR the position or zeroing of this register in the program to set the data direction on the corresponding pin. When a bit is set
For 1 o'clock, the corresponding PIN is the output mode, and when a bit is set to 0 o'clock, the corresponding PIN is the input mode.
4 Port X Control Register 1 PX_CR1 Port control register 1 is used to set some functions of the port. In the port input mode, set the port pull-up mode: 0-Float input, 1-with internal weak pull-up input;
In the port output mode, set the port as open-drain output or push-pull output: 0-Analog open-drain output, 1-push-pull output;
Port X Control Register 2 PX_CR2
In port input mode, set the interrupt for the port:
0-Prohibit external interrupts, 1-enable external interrupts;
In port output mode, set the output slew rate of the port:
0-Low slew rate, output speed max 2m;1-Fast slew rate, output speed max 10M;

Some small reminders of using Gpio
1 after reset, all Gpio are in the suspended input mode
2 Unused pins must be linked to a fixed level.
3 Low power mode halt, if the PA1,PA2 is used to connect an external oscillator, the PA1,PA2 needs to be set to the pull-up input to achieve the lowest power dissipation;
The input function of the ④ pin multiplexing function is used before the corresponding PIN must be set as the input mode;
⑤ pin external interrupt corresponding PIN needs to be set to input mode;
⑥ADC input pin push needs to be set to non-interrupted float input, it is recommended to prohibit Schmitt trigger;
⑦ when the pin is set to SPI, for maximum performance, the corresponding PIN must be set to pull up, fast slew rate;
All GPIO-related registers are cleared 0 after ⑧ reset;

STM8 Beginner to Proficient 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.