当前位置:网站首页>[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Entry 32 MCU and GPIO initialization parameter configuration]
[Jiangsu University Self-Chemistry Association stm32F103c8t6] Notes [Entry 32 MCU and GPIO initialization parameter configuration]
2022-07-30 07:14:00 【Clockwisee】
目录
一、前言
Systematically the other day32Microcontroller to learn a bit,学习的视频是bilibiliof the Jiangxi University of Science and Technologyc8t6的教学,为了方便以后使用,在这里和bStation video linkage to write a note,In order to check the data and call the function by yourself.
二、necessary information
1、C语言类型

- int在51MCU is16位的,在STM32中32位的,如果要用16bits of data to useshort来表示
- float和double都是带符号的,There are no unsigned ones
- 枚举enum的使用,类似于struct结构体,Just assignment and reference are scoped


2、片上资源/外设

3、引脚定义

- 不要轻易使用PA15,PB3,PB4,They are used as debug ports
4、系统结构

性能:AHB>APB2>APB1(Pay attention to the peripherals in these three,In fact, the performance of the latter two is similar)
三、GPIO初始化
1、首先使用RCC开启GPIO的时钟
从APB2总线,引出RCC_APB2PeriphClockCmd(GPIO口的名字,状态),如使GPIOA 使能:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
2、其次使用GPIO_Init函数初始化GPIO
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
第一个参数 GPIO_TypeDef* GPIOx 通过x选定GPIO, 如:GPIOA
第二个参数 GPIO_InitTypeDef* GPIO_InitStruct是GPIO的结构体地址 如:&GPIO_InitStructure
struct 关键字,定义结构体变量
用途:数据打包,Different types of variables are packed(可以数组,Arrays are packed with the same type)#define 新名字 旧名字(Brainless definition)
typedef 旧名字 新名字(定义 Long variable type name);
Because the structure variable type is longer,所以通常用typedefChange the variable type name比如:

将结构体变量 struct{…} Change to another nameGPIO_InitTypeDef
我们把GPIO_InitTypeDef取个名字叫GPIO_InitStructure放到void GPIO_Init()above and invoid GPIO_Init()中取地址&GPIO_InitStructure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure
void GPIO_Init(GPIOA,GPIO_InitTypeDef* GPIO_InitStruct)
由上面struct{…}Structs knowGPIO_InitStructure There are three parameters used respectively.引出:
(也可以用->Just point to the structure member directly,就不必用*取地址和.Extract the structure)
GPIO_InitStructure.GPIO_Mode
GPIO_InitStructure.GPIO_Pin
GPIO_InitStructure.GPIO_Speed
第一个Mode有8种模式
GPIO_Mode_AIN(Analog IN)//模拟输入
GPIO_Mode_IN_FLOATING //浮空输入
GPIO_Mode_IPD (In Pull Down) //下拉输入
GPIO_Mode_IPU (In Pull Up) //上拉输入
GPIO_Mode_OUT_OD(Out Open Drain) //开漏输出
GPIO_Mode_PP_OD(Out Push Pull) //推挽输出
GPIO_Mode_AF_OD(Atl Open Drain) //复用开漏
GPIO_Mode_AF_PP(Atl Push Pull) //复用推挽

- 开漏 高电平没有驱动能力
- 推挽 高低电平都有驱动能力
第二个GPIO_InitStructure.GPIO_Pin 的选择
第三个GPIO_InitStructure.GPIO_Speed的选择
We generally choose50MHz
最后结果如下:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
这样我们就把GPIOA All pins are initialized.
3、Finally use input or output function controlGPIO口
————————————————————————————————————————————————end
All involved hereRCC和GPIO两个外设
*常用的三个RCC外设
void RCC_AHBPeriphClockCmd(uint32_t RCC_AHBPeriph, FunctionalState NewState);
void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
*读写GPIO的8个函数
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
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);
例1:
GPIO_SetBits : Pull high pin output level //1
GPIO_ResetBits :Pull low pin output level //0
GPIO_ResetBits(GPIOA, GPIO_Pin_0); //将PA0口置0
Delay_ms(500);
GPIO_SetBits(GPIOA, GPIO_Pin_0);//将PA0口置1
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_RESET);//Bit_RESET设置低电平
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, Bit_SET);
Delay_ms(500);
GPIO_WriteBit(GPIOA, GPIO_Pin_0, (BitAction)0);//强制转换BitAction类型 0 1
GPIO_WriteBit(GPIOA, GPIO_Pin_0, (BitAction)1);
Delay_ms(500);
例2:读取GPIO上 Level operation
GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13);//读取PB13on pin input Usually a keystroke Read its input That is, whether to press
GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_1)//读取PA1pin out Generally connected to the photosensitive sensor 读它的AO口输出 That is, whether it is blocked
例3:The light function is used
//Turn on the lights
void LED1_ON(void)
{
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}
//The lights go out
void LED1_OFF(void)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}
//The flip of the lamp
void LED1_Turn(void)
{
if (GPIO_ReadOutputDataBit(GPIOA, GPIO_Pin_1) == 0)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}
else
{
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}
}
四、delay,oled函数的调用
1、delay
Delay_us();
Delay_ms();
Delay_s();
Delay.h
#ifndef __DELAY_H
#define __DELAY_H
void Delay_us(uint32_t us);
void Delay_ms(uint32_t ms);
void Delay_s(uint32_t s);
#endif
2、oled

上述代码添加.c和.hIt can be called directly after the file
边栏推荐
猜你喜欢

Flink-stream/batch/OLAP integrated to get Flink engine

基于PyTorch深度学习无人机遥感影像目标检测、地物分类及语义分割

边境的悍匪—机器学习实战:第十二章 使用TensorFlow自定义模型和训练

CNN经典模型发展进程

大气颗粒物 PMF 源解析

QT每周技巧(3)~~~~~~~~~串口添加

BLDC电机应用持续火爆,“网红神器”筋膜枪前景几何?

Self-augmented Unpaired Image Dehazing via Density and Depth Decomposition程序运行记录

QT连载4:基于QT和STM32H750的LORA试验平台(3)

边境的悍匪—机器学习实战:第十五章 使用CNN和RNN处理序列
随机推荐
i++与 ++i 的区别
Through the bit operations to convert the characters are case sensitive
遥感、GIS和GPS技术在水文、气象、灾害、生态、环境及卫生等应用
Pytorch(三):可视化工具(Tensorboard、Visdom)
2021-09-16 集成学习上--task1机器学习数学基础
Target detection, object classification and semantic segmentation of UAV remote sensing images based on PyTorch deep learning
openssl1.1.1ARM dual compilation
Biome-BGC 生态系统模型与应用
基于OpenCV的双目重建
Receive emails from gmail with pop3
XMLBean的基础运用
边境的悍匪—机器学习实战:第二章 端到端的机器学习项目
写在公众号之前——QT,ARM,DSP,单片机,电力电子与传动!
通过位运算进行字符大小写转换
逻辑右移和算术右移区别
虚拟机栈帧结构
QT连载1:readyRead()函数,数据分包不完整解决办法
[Punctuality Atom] Simple application of sys.c, sys.h bit-band operations
高交会重要活动之一|2020中国硬件创新大赛全国总决赛
目标检测中的知识蒸馏方法