当前位置:网站首页>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代表没有发生中断。
边栏推荐
- How many knowledge points can a callable interface have?
- BeanUtils -- shallow copy -- example / principle
- Multi rotor aircraft control using PID and LQR controllers
- Development and design of animation surrounding mall sales website based on php+mysql
- Qt原代码基本知识
- Packet capturing tool Fiddler learning
- TeamTalk源码分析之win-client
- OpenHarmony笔记-----------(四)
- 什么是 eRDMA?丨科普漫画图解
- kaggle如何使用utility script
猜你喜欢

c# 水晶报表打印

Pycharm连接远程服务器

Getting started with QT - making a simple calculator

< schéma de développement de la machine d'exercice oral > machine d'exercice oral / trésor d'exercice oral / trésor de mathématiques pour enfants / lecteur LCD de calculatrice pour enfants IC - vk1621

QT new project_ MyNotepad++

Available solution development oral arithmetic training machine / math treasure / children's oral arithmetic treasure / intelligent math treasure LCD LCD driver ic-vk1622 (lqfp64 package), original te

抓包工具fiddler学习

Error: eacces: permission denied, access to "/usr/lib/node_modules"

How kaggle uses utility script
![[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)](/img/de/7d70f513577e93f1bde1969935a29e.jpg)
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
随机推荐
Design of non main lamp: how to make intelligent lighting more "intelligent"?
Solving the longest subsequence with linear DP -- three questions
BeanUtils -- shallow copy -- example / principle
Fabric.js 手动加粗文本iText
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
Yyds dry goods inventory software encryption lock function
一般来讲,如果频繁出现inconsistent tab and space的报错
Thymeleaf dependency
Understanding of mongodb
< schematic diagram of oral arithmetic exercise machine program development> oral arithmetic exercise machine / oral arithmetic treasure / children's math treasure / children's calculator LCD LCD driv
Story points vs. human days
Fabric.js 橡皮擦的用法(包含恢复功能)
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
A white hole formed by antineutrons produced by particle accelerators
[development environment] 010 editor tool (tool download | binary file analysis template template installation | shortcut key viewing and setting)
In 2021, the global revenue of structural bolts was about $796.4 million, and it is expected to reach $1097.6 million in 2028
Origin plots thermogravimetric TG and differential thermogravimetric DTG curves
Fabric. JS free drawing ellipse
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
P1042 [noip2003 popularization group] Table Tennis