当前位置:网站首页>STM32标准固件库函数名(一)
STM32标准固件库函数名(一)
2022-07-02 11:21:00 【Little BigUs】
操作寄存器 CRH 和 CRL 来配置 IO 口的模式和速度
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);操作 IDR 寄存器读取 IO 端口数据是通过 GPIO_ReadInputDataBit 函数实现的
GPIO_ReadInputData(GPIO_TypeDef * GPIOx) uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)返回值是 1(Bit_SET)或者 0(Bit_RESET);
在固件库中设置 ODR 寄存器的值来控制 IO 口的输出状态是通过函数 GPIO_Write 来实现的
GPIO_WriteBit(GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, BitAction BitVal) GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);通过 BSRR 和 BRR 寄存器设置 GPIO 端口输出是通过函数GPIO_SetBits()和函数 GPIO_ResetBits()来完成的。
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);外设(串口)时钟使能
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1);串口复位
void USART_DeInit(USART_TypeDef* USARTx);串口参数初始化
void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);第一个参数是串口名称,第二个参数是包含初始化参数的结构体指针
数据发送与接收
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data); uint16_t USART_ReceiveData(USART_TypeDef* USARTx);串口状态
串口状态可以通过USART的SR寄存器查看
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-51p4uhTX-1655780674551)(C:\Users\luo’xin\AppData\Roaming\Typora\typora-user-images\image-20220620154658850.png)]
第五位 RXNE(read external not enpty)当该位被置 1 的时候,就是提示已经有数据被接收到了,并且可以读出来了。这时候我们要做的就是尽快去读取 USART_DR,通过读 USART_DR 可以将该位清零,也可以向该位写 0,直接清除。
第六位 TC(transaction complete)当该位被置位的时候,表示 USART_DR 内的数据已经被发送完成了。如果设置了这个位的中断,则会产生中断。该位也有两种清零方式:1)读 USART_SR,写USART_DR。2)直接向该位写 0。
读取串口状态函数:
FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);第一个参数是串口名称,第二个参数是要查看的状态,例如第二个参数可以是USART_FLAG_RXNE, USART_FLAG_TC等等。
串口使能
USART_Cmd(USART_TypeDef * USARTx, FunctionalState NewState)第一个参数不用再说了,第二个参数的可选项有ENABLE , DISABLE。
串口中断配置,可以配置通过什么情形(如 计数溢出,接收到数据,数据发送完成等)可以触发中断
//串口中断配置 USART_ITConfig(USART_TypeDef * USARTx, uint16_t USART_IT, FunctionalState NewState)这个函数的第二个入口参数是标示使能串口的类型,也就是使能哪种中断,因为串口的中断类型有很多种。比如在接收到数据的时候(RXNE 读数据寄存器非空),我们要产生中断,那么我们开启中断的方法是:
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);我们在发送数据结束的时候(TC,发送完成)要产生中断,那么方法是:
USART_ITConfig(USART1,USART_IT_TC,ENABLE);更多的中断使能类型请查阅STM32中文参考手册中USART_CR寄存器
获取相应的中断状态
如果使能了中断,则在中断发生时会在相应的状态寄存器产生位变化,我们通过读取该位就能知道是否发生了中断
USART_GetITStatus(USART_TypeDef * USARTx, uint16_t USART_IT)
变化,我们通过读取该位就能知道是否发生了中断
```
USART_GetITStatus(USART_TypeDef * USARTx, uint16_t USART_IT)
```
返回值是SET , RESET,set代表发生了中断,RESET代表没有发生中断。
边栏推荐
- Fabric.js 自由绘制圆形
- 抓包工具fiddler学习
- 你知道Oracle的数据文件大小有上限么?
- Golang 快速生成数据库表的 model 和 queryset
- Openharmony notes --------- (4)
- Route (II)
- 故事點 vs. 人天
- 联合搜索:搜索中的所有需求
- Certik released the defi security report in 2021, disclosing key data of industry development (PDF download link attached)
- MySQL 45 lecture - learning the actual battle of MySQL in Geek time 45 Lecture Notes - 05 | easy to understand index (Part 2)
猜你喜欢

The conference on the growth of all things was held in Hangzhou, and dangbei was selected into the top 100 list of future unicorns in China in 2022

Default slot, named slot, scope slot
![[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)](/img/e0/e9cb42f241a60995d4598ba6a1a2fe.jpg)
[development environment] Dell computer system reinstallation (download Dell OS recovery tool | use Dell OS recovery tool to make USB flash disk system | install system)

Whole house Wi Fi: a pain point that no one can solve?

2022 home projector preferred! Dangbei F5 brings the ultimate audio-visual experience with its powerful audio-visual effect

每日学习2

Fabric.js 缩放画布

In 2021, the global styrene butadiene styrene (SBS) revenue was about $3722.7 million, and it is expected to reach $5679.6 million in 2028

Fabric. JS upper dash, middle dash (strikethrough), underline

QT new project_ MyNotepad++
随机推荐
由粒子加速器产生的反中子形成的白洞
Fabric.js 手动加粗文本iText
Data consistency between redis and database
Story points vs. human days
kaggle如何使用utility script
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
The global special paper revenue in 2021 was about $27 million, and it is expected to reach $35 million in 2028. From 2022 to 2028, the CAGR was 3.8%
MySQL 45 lecture - learning from the actual battle of geek time MySQL 45 Lecture Notes - 04 | easy to understand index (Part 1)
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
Using computed in uni app solves the abnormal display of data () value in tab switching
Packet capturing tool Fiddler learning
卷积神经网络(入门)
Fabric. Usage of JS eraser (including recovery function)
Fabric. Keep the original level when JS element is selected
Understanding of mongodb
Dangbei projection 4K laser projection X3 Pro received unanimous praise: 10000 yuan projector preferred
快解析:轻松实现共享上网
Fabric. JS upper dash, middle dash (strikethrough), underline
删除元素(带过渡动画)
腾讯云 TStor 统一存储通过信通院首批文件存储基础能力评测