当前位置:网站首页>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);
}
}
边栏推荐
- 解决方案:炼丹师养成计划 Pytorch+DeepLearning遇见的各种报错与踩坑避坑记录(二)
- npm报错, Error: EPERM: operation not permitted, mkdir
- [FPGA tutorial case 30] DDS direct digital frequency synthesizer based on FPGA -- frequency accuracy analysis with MATLAB
- 第五讲—按键控制LED
- TCP的三次握手与四次断开
- Autojs learning - realize the display of date and lunar time
- 静态路由基础配置(IP地址的规划、静态路由的配置),实现全网可达。
- 平面转换(位移、旋转、缩放)
- [explain C language in detail] this article takes you to know C language and makes you impressed
- Experiment of OSPF in mGRE environment
猜你喜欢

RIP V2 的简单应用(v2的配置、宣告、手工汇总、RIPV2的认证、沉默接口、加快收敛)
![[MySQL] MySQL startup and shutdown commands and some error reports to solve problems](/img/23/b4c90604eba796692fbe049d2679d1.png)
[MySQL] MySQL startup and shutdown commands and some error reports to solve problems

2022zui new Tiktok 24-hour round robin live broadcast monitoring (I) live broadcast room start-up monitoring
![[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中的简单静态路由

Mechanical hard disk Selection Guide -- from the selection experience

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

TCP的三次握手与四次挥手(简述)

广域网技术实验

OSPF在MGRE环境下配置及LSA的优化---减少LSA更新量(汇总、特殊区域)
随机推荐
[Database Course Design] SQLSERVER database course design (student dormitory management), course design report + source code + database diagram
WAN technology experiment
关于编程的自我介绍和规划
Text to image论文精读RAT-GAN:文本到图像合成中的递归仿射变换 Recurrent Affine Transformation for Text-to-image Synthesis
通过对射式红外传感器计次实验讲解EXTI中断
初识C语言(1)
广域网技术实验
2022 open source work of the latest text generated image research (papers with code)
OSPF的重发布及路由策略
Text to image论文精读SSA-GAN:基于语义空间感知的文本图像生成 Text to Image Generation with Semantic-Spatial Aware GAN
【mysql】mysql启动关闭命令以及一些报错解决问题
Test and open basic daily question brushing (continuous updating...)
OGeek Meetup第一期,携手CubeFS火热来袭
HCIA(网络初级综合实验练习)
Text to image paper intensive reading ssa-gan: text to image generation with semantic spatial aware Gan
C语言——字符和字符串、算术运算符、类型转换
第五讲—按键控制LED
OSPF static experiment
平面转换(位移、旋转、缩放)
2022zui new Tiktok 24-hour round robin live broadcast monitoring (I) live broadcast room start-up monitoring