STM32 library function GPIO port development

STM32 library function GPIO port development
data reference punctual atom F1 development data

GPIO important functions:

Insert picture description here

Detailed explanation of important functions:

1 initialization function:

void GPIO_Init(GPIO_TypeDef GPIOx,GPIO_InitTypeDef*GPIO_InitStruct); *How to
Insert picture description here
use:
GPIO_Init(GPIOB, &GPIO_InitStructure); Principle of the library:
1. First define a structure, (it is convenient to define the port multiple times) to
Insert picture description here
create a structure, use it Create a structure: GPIO_InitTypeDef GPIO_InitStructure;
2. Configure the structure
Assign values ​​to the corresponding members in the structure;

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; //LED0-->PB.5 端口配置;范围:0~15;
	
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;     //推挽输出
																					 //对应方式:
																					 //GPIO_Mode_AIN = 0x00, 模拟输入
																					 //GPIO_Mode_IN_FLOATING = 0x04, 输入浮空
																					 //GPIO_Mode_IPD = 0x28, 输入下降沿
																					 //GPIO_Mode_IPU = 0x48, 输入上升沿
																					 //GPIO_Mode_Out_OD = 0x14, 开漏输出
																					 //GPIO_Mode_Out_PP = 0x10, 推挽输出
																					 //GPIO_Mode_AF_OD = 0x1C, 复用开漏
																					 //GPIO_Mode_AF_PP = 0x18 复用推挽
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz  、2MHZ 、10MHZ

2 read input level functions:

uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef GPIOx, uint16_t GPIO_Pin); *
Function: Readthe input level of a GPIO . The actual operation is the GPIOx_IDR register.
For example:
GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5);//Read the input level of GPIOA.5, the first one is to define which group. The second is to define which mouth

uint16_t GPIO_ReadInputData(GPIO_TypeDef GPIOx); *
Function: Readthe input level of a certain group of GPIO . The actual operation is the GPIOx_IDR register.
For example:
GPIO_ReadInputData(GPIOA);//Read the input level of all io ports in the GPIOA group and return a 16-bit value

2 functions to read the output level: same as above

uint8_t GPIO_ReadOutputDataBit (GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
Function: Read the output level of a GPIO . The actual operation is the GPIO_ODR register .
For example:
GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_5);//Read the output level of GPIOA.5

uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
Function: Read the output level of a certain group of GPIO . The actual operation is the GPIO_ODR register.
For example:
GPIO_ReadOutputData(GPIOA);//Read the output level of all io ports in the GPIOA group

4 functions to set the output level:

void GPIO_SetBits(GPIO_TypeDef GPIOx, uint16_t GPIO_Pin); *
Function: Set a certain IO port output to high level (1). Actual operation of the BSRR register

void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
Function: Set a certain IO port output to low level (0). The actual operation of the 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 , they are also used to set the output level of the IO port.

eg:
Marquee routine:
1. Enable the IO port clock.
Call function RCC_APB2PeriphColckCmd(); (different IO groups, call clock enable is different)
2. Initialize IO port mode.
Call function: GPIO_Init();
3. Operate the IO port and output high and low levels.
GPIO_SetBits();
GPIO_ResetBits();

Guess you like

Origin blog.csdn.net/qq_45396672/article/details/102859101