当前位置:网站首页>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函数的作用。
边栏推荐
- Unity3d Learning Notes 6 - GPU instantiation (1)
- HDU 4912 paths on the tree (lca+)
- 插入排序与希尔排序
- GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
- China 1,4-cyclohexanedimethanol (CHDM) industry research and investment decision-making report (2022 Edition)
- GPS从入门到放弃(十四)、电离层延时
- [sciter]: encapsulate the notification bar component based on sciter
- Attack and defense world miscall
- [10:00 public class]: basis and practice of video quality evaluation
- A Mexican airliner bound for the United States was struck by lightning after taking off and then returned safely
猜你喜欢

How does the uni admin basic framework close the creation of super administrator entries?

Make menuconfig has a recipe for target 'menuconfig' failed error

Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案

第4章:再谈类的加载器

3DMAX assign face map

Assembly and interface technology experiment 5-8259 interrupt experiment

3DMax指定面贴图

Management background --5, sub classification

Leetcode question brushing (XI) -- sequential questions brushing 51 to 55

GNN, please deepen your network layer~
随机推荐
PVL EDI project case
414. The third largest digital buckle
[sciter bug] multi line hiding
2020 Bioinformatics | GraphDTA: predicting drug target binding affinity with graph neural networks
C#实现水晶报表绑定数据并实现打印4-条形码
GPS from getting started to giving up (19), precise ephemeris (SP3 format)
Management background --1 Create classification
第3章:类的加载过程(类的生命周期)详解
Search element topic (DFS)
What is the difference between animators and animators- What is the difference between an Animator and an Animation?
【sciter】: 基于 sciter 封装通知栏组件
C # realizes crystal report binding data and printing 4-bar code
What a new company needs to practice and pay attention to
anaconda安装第三方包
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
Management background --5, sub classification
十二、启动流程
中国VOCs催化剂行业研究与投资战略报告(2022版)
每日一题:力扣:225:用队列实现栈
Wechat red envelope cover applet source code - background independent version - source code with evaluation points function