当前位置:网站首页>STM32 --- GPIO configuration & GPIO related library functions
STM32 --- GPIO configuration & GPIO related library functions
2022-07-05 08:15:00 【chen_ bx】
STM32---GPIO Configuration of library functions & GPIO Related library functions
gpio file
The header file :stm32f10x_gpio.h
Source file :stm32f10x_gpio.c
To configure GPIO step
① Can make IO Port clock .
Call function
RCC_APB2PeriphColckCmd();
Different IO Group , The clock enable function called is different .
② Initialization function
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
effect : Initialize one or more IO mouth ( The same group ) How and speed .
This function mainly operates GPIO_CRL(CRH) register , Pull up or down
When is it set BSRR perhaps BRR register
GPIOx: GPIOA~GPIOG
The initialization structure is as follows
typedef struct
{
uint16_t GPIO_Pin; // Specify the to initialize IO mouth
GPIOSpeed_TypeDef GPIO_Speed; // Set up IO Port output speed
GPIOMode_TypeDef GPIO_Mode; // Set the working mode :8 One of the species
}GPIO_InitTypeDef;
Be careful : peripherals ( Include GPIO) Before use , Almost always enable the corresponding clock first .
GPIO Initialization example :
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);// open GPIOB The clock
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 port configuration
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO The mouth speed is 50MHz
GPIO_Init(GPIOB, &GPIO_InitStructure); // Initialize according to the set parameters GPIOB.5
You can initialize one at a time IO Multiple under group IO, The premise is that these IO The configuration of ports is the same .
GPIO Related library functions
2 A read input level function :
①
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
effect : Read something GPIO The input level of . The actual operation is GPIOx_IDR register .
for example :
GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5);// Read GPIOA.5 The input level of
②
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
effect : Read a group GPIO The input level of . The actual operation is GPIOx_IDR register .
for example :
GPIO_ReadInputData(GPIOA);// Read GPIOA All in the group io Port input level
2 A read output level function :
①
uint8_t GPIO_ReadOutputDataBit (GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
effect : Read something GPIO Output level of . The actual operation is GPIO_ODR register .
for example :
GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5);// Read GPIOA.5 Output level of
②
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
effect : Read a group GPIO Output level of . The actual operation is GPIO_ODR register .
for example :
GPIO_ReadOutputData(GPIOA);// Read GPIOA All in the group io Port output level
4 Set the output level function :
①
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
effect : Set up a IO The output of the port is high (1). Actual operation BSRR register
②
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
effect : Set up a IO The output of the port is low (0). In practice BRR register .
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
These two functions are not commonly used , It's also used to set up IO Port output level .
This article refers to the notes on punctual atoms
边栏推荐
- NTC thermistor application - temperature measurement
- How to define guid in AMI code
- STM32 outputs 1PPS with adjustable phase
- C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
- Naming rules for FreeRTOS
- Solutions to compilation warnings in Quartus II
- Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
- C WinForm [display real-time time in the status bar] - practical exercise 1
- Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
- 【云原生 | 从零开始学Kubernetes】三、Kubernetes集群管理工具kubectl
猜你喜欢

Consul安装
![Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine](/img/55/0f05291755dc1c3c03db8e991a1ba1.jpg)
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
![C WinForm [help interface - send email] - practice five](/img/2a/c4e7abe054e6fdd45acc7d297a033d.jpg)
C WinForm [help interface - send email] - practice five

DokuWiki deployment notes

Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)

The firmware of the connected j-link does not support the following memory access

My-basic application 2: my-basic installation and operation

How to select conductive slip ring

Why is 1900 not a leap year

MySQL MHA high availability cluster
随机推荐
Imx6ull bare metal development learning 2- use C language to light LED indicator
OC and OD gate circuit
Summary of SIM card circuit knowledge
动力电池UL2580测试项目包括哪些
FIO测试硬盘性能参数和实例详细总结(附源码)
DCDC circuit - function of bootstrap capacitor
Baiwen 7-day smart home learning experience of Internet of things
Take you to understand the working principle of lithium battery protection board
Factors affecting the quality of slip rings in production
Why is 1900 not a leap year
Step motor generates S-curve upper computer
Problem solving: interpreter error: no file or directory
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
Anonymous structure in C language
Bluetooth hc-05 pairing process and precautions
Brief discussion on Buck buck circuit
Carrier period, electrical speed, carrier period variation
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
Define in and define out
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address