当前位置:网站首页>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
函数的作用。
边栏推荐
- QT | UDP broadcast communication, simple use case
- 第4章:再谈类的加载器
- [10:00 public class]: basis and practice of video quality evaluation
- Unity3d Learning Notes 6 - GPU instantiation (1)
- 数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据
- Shell product written examination related
- Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
- MariaDB database management system learning (I) installation diagram
- GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
- Research and investment strategy report of China's VOCs catalyst industry (2022 Edition)
猜你喜欢
3DMax指定面贴图
图像的spatial domain 和 frequency domain 图像压缩
墨西哥一架飞往美国的客机起飞后遭雷击 随后安全返航
Management background --2 Classification list
GPS从入门到放弃(十四)、电离层延时
UNI-Admin基础框架怎么关闭创建超级管理员入口?
3DMAX assign face map
Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
小常识:保险中的“保全”是什么?
PVL EDI project case
随机推荐
GPS从入门到放弃(十七) 、对流层延时
第3章:类的加载过程(类的生命周期)详解
Management background --2 Classification list
C#实现水晶报表绑定数据并实现打印4-条形码
Xiaoman network model & http1-http2 & browser cache
zabbix 代理服务器 与 zabbix-snmp 监控
C#實現水晶報錶綁定數據並實現打印4-條形碼
OpenCV300 CMake生成project在项目过程中的问题
Attack and defense world miscall
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
CCNA Cisco network EIGRP protocol
嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
Adjustable DC power supply based on LM317
[leetcode daily clock in] 1020 Number of enclaves
基于 QEMUv8 搭建 OP-TEE 开发环境
PVL EDI project case
0 basic learning C language - interrupt
GNN, please deepen your network layer~
Bat script learning (I)
LeetCode刷题(十一)——顺序刷题51至55