当前位置:网站首页>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代表没有发生中断。
边栏推荐
- 测试框架TestNG的使用(二):testNG xml的使用
- Fabric. Keep the original level when JS element is selected
- Fabric.js 手动加粗文本iText
- 故事點 vs. 人天
- MySQL45讲——学习极客时间MySQL实战45讲笔记—— 04 | 深入浅出索引(上)
- Basic knowledge of QT original code
- Advanced usage of C language -- function pointer: callback function; Conversion table
- TeamTalk源码分析之win-client
- Solving the longest subsequence with linear DP -- three questions
- Design of non main lamp: how to make intelligent lighting more "intelligent"?
猜你喜欢
What is erdma? Popular science cartoon illustration
There is no solution to the decryption error of the remote user 'sa' and the service master password mapped from the remote server 'to the local user' (null) /sa '
Tip: SQL Server blocked the state 'openrowset/opendatasource' of component 'ad hoc distributed queries'
[development environment] StarUML tool (download software | StarUML installation | StarUML creation project)
提示:SQL Server 阻止了对组件‘Ad Hoc Distributed Queries ‘的STATEMENT ‘OpenRowset/OpenDatasource“”
Use of swagger
Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
Fabric.js 缩放画布
【虹科技术分享】如何测试 DNS 服务器:DNS 性能和响应时间测试
Pychart connects to the remote server
随机推荐
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 05 | 深入浅出索引(下)
途家木鸟美团夏日折扣对垒,门槛低就一定香吗?
QT new project_ MyNotepad++
Fabric.js 手动加粗文本iText
Solve the problem that openocd fails to burn STM32 and cannot connect through SWD
千元投影小明Q1 Pro和极米NEW Play谁更好?和哈趣K1比哪款配置更高?
Fabric.js 橡皮擦的用法(包含恢复功能)
Go operation redis
Who is better, Qianyuan projection Xiaoming Q1 pro or Jimi new play? Which configuration is higher than haqu K1?
A white hole formed by antineutrons produced by particle accelerators
The most complete analysis of Flink frame window function
Basic knowledge of QT original code
Thymeleaf dependency
Understanding of mongodb
P1908 逆序对
Golang quickly generates model and queryset of database tables
Data consistency between redis and database
Using computed in uni app solves the abnormal display of data () value in tab switching
Design of non main lamp: how to make intelligent lighting more "intelligent"?
跨服务器数据访问的创建链接服务器方法