当前位置:网站首页>Lecture 3 - GPIO input / output library function usage and related routines
Lecture 3 - GPIO input / output library function usage and related routines
2022-07-27 02:16:00 【Ruomu·】
Catalog
One 、 Add the missing content in the first lecture
1.stm32 Naming rules of development board :
Two .GPIO Input and output related library functions
1. Need to master first GPIO function
1.GPIO_SetBits() Function and GPIO_ResetBits function :
2.GPIO_WriteBit Function and GPIO_Write function :
2. Lighten up LED and LED flashing
Preface
The last lecture introduced GPIO What is it? ,GPIO Eight working modes of , In detail GPIO Initialize the configuration method , Here is a detailed introduction GPIO Input the usage of related library functions and use related routines for your reference
One 、 Add the missing content in the first lecture
When the project folder is established and the relevant library is imported , After the questions of the little partner, I found that I missed a more important content , That is how to choose according to the development board model user Startup file in , Let's give you a detailed introduction :
1.stm32 Naming rules of development board :
Want to know how to choose the right startup file , First of all, be clear stm32 Naming rules of series development boards , With what I use stm32f103c8t6 For example ,
Divide it into STM32 F 103C8 T6
Stm32 That is to say 32 Single chip microcomputer ,
F It's the product type ,103 Represents the product sub series ,101 Basic type ,102 by USB Basic type ,103 It is enhanced ,105 or 107 It is interconnected .
C Number of representative pins ,T=36 foot ,C=48 foot ,R=64 foot ,V=100 foot ,Z=144 foot .
8 representative FLASH size ( It can be understood as flash memory )6=32K,8=64K,B=128K,C=256K,D=384K,E=512K
T Representative package H=BGA T=LQFP,U=VFQFPN
6 Represents the operating temperature range 6= Industrial grade ,-40~+85℃ 7= Industrial grade ,-40~+105℃
2. Model classification
Classify according to their model
| model | Flash Capacity | abbreviation |
| STM32F100 | 16-32K | LD_VL |
| STM32F100 | 64-128K | MD_VL |
| STM32F100 | 256-512K | HD_VL |
| STM32F101/102/103 | 16-32K | LD |
| STM32F101/102/103 | 64-128K | MD |
| STM32F101/102/103 | 256-512K | HD |
| STM32F101/102/103 | >512K | XL |
| STM32F105/107 | -- | CL |
therefore , We use F103C8T6 Is it just a choice MD,s The startup file of :?
Obviously !
Two .GPIO Input and output related library functions
First of all, let's talk about it GPIO The relevant library functions of input and output are in the GPIO.h In file , Drop down to the end to find .
1. Need to master first GPIO function
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
These are the most commonly used for beginners GPIO function , Let's introduce... One by one :
1.GPIO_SetBits() Function and GPIO_ResetBits function :
Used to configure GPIO The port is high level ,LED You can use this function to turn off the light in , Where the parameters of the function are the same as GPIO The parameters of the initialization function are the same , Another example is how to choose parameters , First look at the comments about parameters in the function definition .
* @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
* @param GPIO_Pin: specifies the port bits to be written.
Illustrate with examples , Suppose we connect peripherals to PA0 mouth , that GPIOx This parameter uses GPIOA, The second parameter is GPIO_Pin_0, So the parameter of this function is (GPIOA,GPIO_Pin_0)
The lower one GPIO_ResetBits Function is also this parameter selection method ,LED You can use this function to turn off the light in , And this function Used to configure GPIO The port is low level .
2.GPIO_WriteBit Function and GPIO_Write function :
GPIO_WriteBit This function has three arguments , Unlike the above function , This function takes three arguments , This parameter is also an implementation GPIO High and low level setting of port , Here's an example :
First look at the function parameter comments :
* @param GPIOx: where x can be (A..G) to select the GPIO peripheral.
* @param GPIO_Pin: specifies the port bit to be written.
* This parameter can be one of GPIO_Pin_x where x can be (0..15).
* @param BitVal: specifies the value to be written to the selected bit.
* This parameter can be one of the BitAction enum values:
* @arg Bit_RESET: to clear the port pin
* @arg Bit_SET: to set the port pin
We still use A0 Take the mouth as an example : Then the first and second parameters are the same as the function described above , Respectively GPIOA and GPIO_PIN_0, Focus on the third parameter , If you want to A0 Set the port to high level , That is, the setting port signal mentioned in the note (to set the port pin), Parameter selection Bit_SET, conversely , That is to clear the port signal (to set the port pin), The parameter is Bit_RESET.
Yes, of course , If you especially want to use 1 and 0 Indicates high and low level , It's fine too , But you need to do a forced conversion , Convert to BitAction, The third parameter is ((BitAction)1) or ((BitAction)0). But not recommended .
And the other function GPIO_Write, All ports can be operated , We will introduce this in detail in the next article .
2. Lighten up LED and LED flashing
After learning the above functions , It can be lit LED Operation , Let's just say LED flashing , It contains points LED The operation of .
First turn on the GPIO Initialization is complete , I already talked about it last class , Here we use , No, you can go to my last blog to have a look . And then use GPIO_SetBits() Lights out ,GPIO_ResetBits() Lighting , Adding delay is flashing .
The attached code :
#include "stm32f10x.h" // Device header
#include "Delay.h"
int main()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// Use RCC Turn on GPIO The clock
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz ;
GPIO_Init(GPIOA,&GPIO_InitStructure);
// Up to the top ,GPIO Initialization complete
while(1)
{
GPIO_ResetBits(GPIOA,GPIO_Pin_0);
GPIO_SetBits(GPIOA,GPIO_Pin_0);
Delay_ms(500);
GPIO_WriteBit(GPIOA,GPIO_Pin_0, Bit_RESET);
//GPIO_WriteBit(GPIOA,GPIO_Pin_0, (BitAction)0);
Delay_ms(500);
GPIO_WriteBit(GPIOA,GPIO_Pin_0, Bit_SET); //GPIO_WriteBit(GPIOA,GPIO_Pin_0, (BitAction)1);
Delay_ms(500);
}
}
边栏推荐
- 动态路由rip协议实验
- HCIA动态路由OSPF实验
- TCP's three handshakes and four waves (brief introduction)
- 【数据库课程设计】SQLServer数据库课程设计(学生宿舍管理),课设报告+源码+数据库关系图
- Pseudo class of a element
- OSPF在MGRE环境下的实验
- JS logical operator
- [explain C language in detail] takes you to play with functions
- C语言——while语句、dowhile语句、for循环和循环结构、break语句和continue语句
- Unity Huatuo hot update environment installation and sample project
猜你喜欢

二层封装技术(HDLC、PPP--PAP\CHAP、GRE)实验练习
![[explain C language in detail] takes you to play with loop structure (for_while_do while)](/img/d9/75053297873a5b5458514e7f557cdc.png)
[explain C language in detail] takes you to play with loop structure (for_while_do while)

ensp中的简单静态路由

Solution to high collapse

Nat网络地址转换实验

FID指标复现踩坑避坑 文本生成图像FID定量实验全流程复现(Fréchet Inception Distance )定量评价实验踩坑避坑流程

7.7 sheen Xiyin written test

高度塌陷解决方法

C语言——关系运算符和逻辑运算符、if语句、switch语句、分支结构的嵌套

STM32入门教程第一讲
随机推荐
The basic configuration of static routing (planning of IP address and configuration of static routing) realizes the accessibility of the whole network.
选择器的使用语法与场景以及背景图片大小、文字盒子阴影、过度效果的使用方法
7.8 锐捷网络笔试
最新C语言入门与进阶 -史上最全最详细的C语言教程!! 第一节-总览C语言概括
通过对射式红外传感器计次实验讲解EXTI中断
Mechanical hard disk Selection Guide -- from the selection experience
Dynamic routing rip protocol experiment
Text to image paper intensive reading rat-gan: recursive affine transformation for text to image synthesis
[FPGA tutorial case 28] one of DDS direct digital frequency synthesizers based on FPGA -- principle introduction
2022 open source work of the latest text generated image research (papers with code)
Electron FAQ 61 - must the client run with administrator privileges?
TIM输出比较——PWM
Ospf基础配置应用( 综合实验: 干涉选举 缺省路由 区域汇总 认证--接口认证)
C语言——字符和字符串、算术运算符、类型转换
First knowledge of Web Design
超出隐藏显示省略号
【volatile原理】volatile原理
解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(二)
[MySQL] MySQL startup and shutdown commands and some error reports to solve problems
动态路由ofps协议配置