当前位置:网站首页>GD32F4XX串口接收中断和闲时中断配置
GD32F4XX串口接收中断和闲时中断配置
2022-07-06 14:29:00 【fangye945a】
最近在调试GD32F4xx,想使用串口的闲时中断,发现与STM32有些区别。在此做个记录,备忘,防止重复踩坑。
串口使能中断相关代码:
nvic_irq_enable(USART0_IRQn,0,1);
usart_interrupt_enable(USART0, USART_INT_RBNE); /* 使能USART0读区非空中断 */
usart_interrupt_enable(USART0, USART_INT_IDLE); /* 使能USART0空闲中断 */
串口中断处理函数:
void USART0_IRQHandler(void)
{
if ((RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE)) &&
(RESET != usart_flag_get(USART0, USART_FLAG_RBNE))) {
unsigned char value = usart_data_receive(USART0);
RingBufWrite(g_debugRingBuf, value); //将接收到的数据写入ringbuf中
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_RBNE); //清中断标志
}
else if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE)) {
usart_interrupt_flag_clear(USART0, USART_INT_FLAG_IDLE);
usart_data_receive(USART0); /* 清除接收完成标志位 */
(void)LOS_EventWrite(&g_shellInputEvent, 0x1); //事件通知接收完成
}
}
特别要注意的是:与STM32F4不同的是,在进入闲时中断后,需要调用usart_data_receive函数,用于清除接收完成标志位,否则闲时中断会存在被触发多次或不触发的情况。
在STM32f4xx中,清除闲时中断标志宏定义如下:
/** @brief Clears the UART IDLE pending flag. * @param __HANDLE__ specifies the UART Handle. * UART Handle selects the USARTx or UARTy peripheral * (USART,UART availability and x,y values depending on device). * @retval None */
#define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
/** @brief Clears the UART PE pending flag. * @param __HANDLE__ specifies the UART Handle. * UART Handle selects the USARTx or UARTy peripheral * (USART,UART availability and x,y values depending on device). * @retval None */
#define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \ do{
\ __IO uint32_t tmpreg = 0x00U; \ tmpreg = (__HANDLE__)->Instance->SR; \ tmpreg = (__HANDLE__)->Instance->DR; \ UNUSED(tmpreg); \ } while(0U)
可以看到有读取操作对DR寄存器进行读取操作,相当于GD32标准库中usart_data_receive函数的作用。
边栏推荐
- labelimg的安装与使用
- Applet system update prompt, and force the applet to restart and use the new version
- 嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
- 【10点公开课】:视频质量评价基础与实践
- Oracle性能分析3:TKPROF简介
- GPS from entry to abandonment (XIV), ionospheric delay
- 【sciter】: 基于 sciter 封装通知栏组件
- 设置状态栏样式Demo
- 【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
- 中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
猜你喜欢

AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing

CCNA-思科网络 EIGRP协议

二叉(搜索)树的最近公共祖先 ●●

Assembly and interface technology experiment 5-8259 interrupt experiment

2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks

第4章:再谈类的加载器

数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据

Powerful domestic API management tool

Search element topic (DFS)

每日一题:力扣:225:用队列实现栈
随机推荐
hdu 4912 Paths on the tree(lca+馋)
GPS从入门到放弃(十一)、差分GPS
Shell product written examination related
GPS from entry to abandonment (XVII), tropospheric delay
2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
OpenCV VideoCapture. Get() parameter details
Management background --1 Create classification
PVL EDI 项目案例
The nearest common ancestor of binary (search) tree ●●
Management background --2 Classification list
MariaDB database management system learning (I) installation diagram
数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据
2500个常用中文字符 + 130常用中英文字符
Some problems about the use of char[] array assignment through scanf..
Powerful domestic API management tool
RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
Oracle control file and log file management
第3章:类的加载过程(类的生命周期)详解