当前位置:网站首页>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
函数的作用。
边栏推荐
- Memorabilia of domestic database in June 2022 - ink Sky Wheel
- HDU 4912 paths on the tree (lca+)
- 【sciter】: 基于 sciter 封装通知栏组件
- 设置状态栏样式Demo
- [线性代数] 1.3 n阶行列式
- Shell product written examination related
- 嵌入式常用计算神器EXCEL,欢迎各位推荐技巧,以保持文档持续更新,为其他人提供便利
- 经纪xx系统节点VIP案例介绍和深入分析异常
- Solve project cross domain problems
- [10:00 public class]: basis and practice of video quality evaluation
猜你喜欢
每日一题:力扣:225:用队列实现栈
2022年6月国产数据库大事记-墨天轮
2500 common Chinese characters + 130 common Chinese and English characters
GPS from getting started to giving up (16), satellite clock error and satellite ephemeris error
GPS从入门到放弃(十九)、精密星历(sp3格式)
AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
RESNET rs: Google takes the lead in tuning RESNET, and its performance comprehensively surpasses efficientnet series | 2021 arXiv
PVL EDI project case
A Mexican airliner bound for the United States was struck by lightning after taking off and then returned safely
Memorabilia of domestic database in June 2022 - ink Sky Wheel
随机推荐
GPS from getting started to giving up (12), Doppler constant speed
zabbix 代理服务器 与 zabbix-snmp 监控
C # réalise la liaison des données du rapport Crystal et l'impression du Code à barres 4
中国VOCs催化剂行业研究与投资战略报告(2022版)
Oracle control file and log file management
中国1,4-环己烷二甲醇(CHDM)行业调研与投资决策报告(2022版)
Unity3d Learning Notes 6 - GPU instantiation (1)
MariaDb数据库管理系统的学习(一)安装示意图
Spatial domain and frequency domain image compression of images
GPS from getting started to giving up (XV), DCB differential code deviation
Kohana 数据库
GPS从入门到放弃(十五)、DCB差分码偏差
Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
C # realizes crystal report binding data and printing 4-bar code
2500 common Chinese characters + 130 common Chinese and English characters
十二、启动流程
GPS from getting started to giving up (16), satellite clock error and satellite ephemeris error
GPS從入門到放弃(十三)、接收機自主完好性監測(RAIM)
图像的spatial domain 和 frequency domain 图像压缩