"STM" IO port configuration library functions, registers, bit operation mode

Source: Internet
Author: User

Library function functions:

An initialization function: Initializes the operating mode, output type, speed, and pull-down mode of one or more IO ports (the same group)

1 voidGpio_init (gpio_typedef* Gpiox, gpio_inittypedef*gpio_initstruct);2typedefstruct3 {4uint32_t Gpio_pin//Specify the port to initialize5Gpiomode_typedef Gpio_mode;//Port Mode6Gpiospeed_typedef Gpio_speed;//Speed7Gpiootype_typedef Gpio_otype;//Output Type8Gpiopupd_typedef gpio_pupd;//pull up or pull down9}gpio_inittypedef;
0 Gpio_init Function Initialization example:   
1 gpio_inittypedef gpio_initstructure;2 3Rcc_ahb1periphclockcmd (Rcc_ahb1periph_gpiof, ENABLE);//Enable GPIOF clock4 5 //GPIOF9,F10 Initialization Settings6Gpio_initstructure.gpio_pin = Gpio_pin_9 | gpio_pin_10;//LED0 and LED1 corresponding IO ports7Gpio_initstructure.gpio_mode = Gpio_mode_out;//Normal Output mode8Gpio_initstructure.gpio_otype = gpio_otype_pp;//push-Pull output9Gpio_initstructure.gpio_speed = Gpio_speed_100mhz;//100MHzTenGPIO_INITSTRUCTURE.GPIO_PUPD = gpio_pupd_up;//Pull Up OneGpio_init (Gpiof, &gpio_initstructure);//Initialize GPIOF9,F10

Two read input level functions:

uint8_t gpio_readinputdatabit (gpio_typedef* gpiox, uint16_t gpio_pin); Read input level of a GPIO
uint16_t Gpio_readinputdata (gpio_typedef* gpiox); Read input level of a set of GPIO

Two read output level functions:

uint8_t gpio_readoutputdatabit (gpio_typedef* gpiox, uint16_t gpio_pin); Read the output level of a GPIO
uint16_t Gpio_readoutputdata (gpio_typedef* gpiox); Read output level of a set of GPIO

Four sets the output level function:

void Gpio_setbits (gpio_typedef* gpiox, uint16_t gpio_pin), setting an IO port output high
void Gpio_resetbits (gpio_typedef* gpiox, uint16_t gpio_pin), setting an IO port output low level

Below two not commonly used
void Gpio_writebit (gpio_typedef* gpiox, uint16_t gpio_pin, bitaction bitval);
void Gpio_write (gpio_typedef* gpiox, uint16_t portval);

library function steps:

Enable IO port clock, call function Rcc_ahb1periphclockcmd ();
The clock enable function may not be the same for different peripheral calls
Initialize IO port mode, call function Gpio_init ();
Operation IO port, output high and low level.
Gpio_setbits ();
Gpio_resetbits ();

"STM" IO port configuration library functions, registers, bit operation mode

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.