> 脸上过敏感冒反反复复老不好怎么没得好啊,怎么回事

13被浏览33,392分享邀请回答104 条评论分享收藏感谢收起0添加评论分享收藏感谢收起写回答查看: 6377|回复: 11
USART1-&SR中的TXE清不掉,反复进入USART1中断处理函数
本人最近做一个串口数据接收到程序。芯片是STM32F103RB。
程序启动后初始化
void& & & & USART1_Init()
& & & & USART_InitTypeDef USART_InitS
& & & & NVIC_InitTypeDef NVIC_InitS
& & & & GPIO_InitTypeDef&&GPIO_InitS
& & & & //给USART1提供时钟
& & & & RCC_APB2PeriphClockCmd(RCC_APB2ENR_USART1EN | RCC_APB2ENR_AFIOEN, ENABLE);& & & &
& & & & /**
& & & && &* 引脚配置 & & & &
& & & && &* TX -& PA9&&推挽输出 1011
& & & && &* RX -& PA10 悬浮输入 0100
& & & && &*/
& & & & //给GPIOA提供时钟
& & & & RCC_APB2PeriphClockCmd( RCC_APB2ENR_IOPAEN, ENABLE);& & & &
& & & & GPIO_PinRemapConfig(GPIO_Remap_USART1, DISABLE);& & & & //不重映射
& & & & & & & &
& & & & GPIO_InitStructure.GPIO_Pin& &= GPIO_Pin_9 ;
& & & & GPIO_InitStructure.GPIO_Mode&&= GPIO_Mode_AF_PP ;
& & & & GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MH
& & & & GPIO_Init(GPIOA,&GPIO_InitStructure);
& & & & GPIO_InitStructure.GPIO_Pin& &= GPIO_Pin_10 ;
& & & & GPIO_InitStructure.GPIO_Mode&&= GPIO_Mode_IPU ;
& & & & GPIO_Init(GPIOA,&GPIO_InitStructure);
& & & & USART_InitStructure.USART_BaudRate& && && && &= USART1_INIT_BAUDRATE&&;
& & & & USART_InitStructure.USART_WordLength& && && & = USART_WordLength_8b;
& & & & USART_InitStructure.USART_StopBits& && && && &= USART_StopBits_1;
& & & & USART_InitStructure.USART_Parity& && && && &&&= USART_Parity_N
& & & & USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_N
& & & & USART_InitStructure.USART_Mode& && && && && & = USART_Mode_Rx | USART_Mode_Tx;
& & & & USART_Init(USART1, &USART_InitStructure);
& & & & USART_ITConfig(USART1, USART_IT_RXNE , ENABLE);
& & & & USART_Cmd(USART1, ENABLE);
& & & & NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
& & & & NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
& & & & NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
& & & & NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
& & & & NVIC_Init(&NVIC_InitStructure);
我只开了USART1的RXNE中断信号。
在串口中断的处理:
void USART1_IRQHandler(void)
& & & & OSIntEnter();
& & & & if( USART1-&SR & USART_SR_RXNE ){
& & & & & & & & uint16_t& & & & RxData = USART_ReceiveData(USART1);& & & &
& & & & & & & & USART1-&SR &= ~(INT32U)USART_SR_RXNE;
& & & & & & & & ……
& & & & if( USART1-&SR & USART_SR_TXE ){
& & & & & & & & USART1-&SR &= ~(INT32U)USART_SR_TXE;& & & &
& & & & OSIntExit();
如果不向设备要送数据,就没有问题。但是,如果我用SSCOM32串口调试助手工具软件往USART1每隔1ms发送一串数据。
开始系统还能正常运行,但后来系统就死了。
查看原因,系统反复进入void USART1_IRQHandler(void)处理函数。USART1-&SR的TXE置位,但在中断函数里又清不掉。所以,系统重复进入中断,后台没有执行的机会。
我的问题是:我明明只使能了RXNEIE,没有使能TXEIE,怎么会有TXE引起的中断产生呢?
有没有遇到类似问题的前辈?这是怎么回事儿?你们是怎么解决的?
我将中断处理函数改成:
void USART1_IRQHandler(void)
& & & & INT32U& & & & State = USART1-&SR;
& & & & OSIntEnter();
& & & & if( State & USART_SR_RXNE ){
& & & & & & & & uint16_t& & & & RxData = USART_ReceiveData(USART1);& & & &
& & & & & & & & ……
& & & & OSIntExit();
用State来存放SR中的状态值,避免多次读SR。
但我遇到了一个更诡异的事情。我用的是MDK V3.80,我发现程序正常运行一分多钟就不动。单步进行调试,在void USART1_IRQHandler(void)中加断点,结果程序执行到中断。接下来,我继续运行,系统又能正常运行一会儿。
如此周而复始……
看不出来哪里问题....
不过 TXE 貌似是硬件清除的, 把相关代码如
if( USART1-&SR & USART_SR_TXE ){
USART1-&SR &= ~(INT32U)USART_SR_TXE;
注释掉试试呢?
STM32的库函数中说明:
&&* @brief&&Clears the USARTx's pending flags.
&&* @param&&USARTx: Select the USART or the UART peripheral.
&&*& &This parameter can be one of the following values:
&&*& &USART1, USART2, USART3, UART4 or UART5.
&&* @param&&USART_FLAG: specifies the flag to clear.
&&*& &This parameter can be any combination of the following values:
&&*& &&&@arg USART_FLAG_CTS:&&CTS Change flag (not available for UART4 and UART5).
&&*& &&&@arg USART_FLAG_LBD:&&LIN Break detection flag.
&&*& &&&@arg USART_FLAG_TC:& &Transmission Complete flag.
&&*& &&&@arg USART_FLAG_RXNE: Receive data register not empty flag.
&&*& &- PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
&&*& &&&error) and IDLE (Idle line detected) flags are cleared by software
&&*& &&&sequence: a read operation to USART_SR register (USART_GetFlagStatus())
&&*& &&&followed by a read operation to USART_DR register (USART_ReceiveData()).
&&*& &- RXNE flag can be also cleared by a read to the USART_DR register
&&*& &&&(USART_ReceiveData()).
&&*& &- TC flag can be also cleared by software sequence: a read operation to
&&*& &&&USART_SR register (USART_GetFlagStatus()) followed by a write operation
&&*& &&&to USART_DR register (USART_SendData()).
&&*& &- TXE flag is cleared only by a write to the USART_DR register
&&*& &&&(USART_SendData()).
&&* @retval None
void USART_ClearFlag(USART_TypeDef* USARTx, uint16_t USART_FLAG)
&&* @brief&&Clears the USARTx抯 interrupt pending bits.
&&* @param&&USARTx: Select the USART or the UART peripheral.
&&*& &This parameter can be one of the following values:
&&*& &USART1, USART2, USART3, UART4 or UART5.
&&* @param&&USART_IT: specifies the interrupt pending bit to clear.
&&*& &This parameter can be one of the following values:
&&*& &&&@arg USART_IT_CTS:&&CTS change interrupt (not available for UART4 and UART5)
&&*& &&&@arg USART_IT_LBD:&&LIN Break detection interrupt
&&*& &&&@arg USART_IT_TC:& &Transmission complete interrupt.
&&*& &&&@arg USART_IT_RXNE: Receive Data register not empty interrupt.
&&*& &- PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun
&&*& &&&error) and IDLE (Idle line detected) pending bits are cleared by
&&*& &&&software sequence: a read operation to USART_SR register
&&*& &&&(USART_GetITStatus()) followed by a read operation to USART_DR register
&&*& &&&(USART_ReceiveData()).
&&*& &- RXNE pending bit can be also cleared by a read to the USART_DR register
&&*& &&&(USART_ReceiveData()).
&&*& &- TC pending bit can be also cleared by software sequence: a read
&&*& &&&operation to USART_SR register (USART_GetITStatus()) followed by a write
&&*& &&&operation to USART_DR register (USART_SendData()).
&&*& &- TXE pending bit is cleared only by a write to the USART_DR register
&&*& &&&(USART_SendData()).
&&* @retval None
void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT)
回复【2楼】wowbanui
-----------------------------------------------------------------------
关键问题是,我只开了RXNE,没有让其它的影响中断。为什么RXNE为0时,还会进入中断呀?
我现在遇到一个更为诡异的问题,系统运行一阵,就不动了。
明白用示波器量量看晶振是不是停了。
系统程序还是在跑,只中就是一直产生USART1中断,中断原因不明。
发送中断清不掉的,关闭它!
问题解决了!
我将中断处理函数改成了:
void USART1_IRQHandler(void)
& & & & uint32_t& & & & State = USART1-&SR;
& & & & uint16_t& & & & RxData = USART1-&DR;
& & & & OSIntEnter();
& & & & if( State & USART_FLAG_RXNE ){
& & & & & & & & //接收处理……
& & & & OSIntExit();
也就是说,不管它是由于什么引起的中断,一进来就读SR与DR,这样可以清掉许多状态位,如:PE,RXNE,IDLE,ORE,NE,FE,PE。
正说库中注解所言:
&&*& &- PE (Parity error), FE (Framing error), NE (Noise error), ORE (OverRun&&
&&*& &&&error) and IDLE (Idle line detected) pending bits are cleared by&&
&&*& &&&software sequence: a read operation to USART_SR register&&
&&*& &&&(USART_GetITStatus()) followed by a read operation to USART_DR register&&
&&*& &&&(USART_ReceiveData()).
&&*& &- RXNE pending bit can be also cleared by a read to the USART_DR register&&
&&*& &&&(USART_ReceiveData()).
&&*& &- TC pending bit can be also cleared by software sequence: a read&&
&&*& &&&operation to USART_SR register (USART_GetITStatus()) followed by a write&&
&&*& &&&operation to USART_DR register (USART_SendData()).
我花了三天时间调个这BUG,希望有遇到类似问题的朋友有所帮助。
回复【7楼】hevake_lcj&&临峰不畏
-----------------------------------------------------------------------
真的吗,试试看
碰到楼主一样的问题,明天试试看
顶,太好了。我也遇到这个问题了。
相同的问题,谢谢lz提供的思路
阿莫电子论坛, 原"中国电子开发网"
, 原www.ourdev.cn, 原www.ouravr.com>> >>脸上过敏反反复复。这是为什么呢?要吃些什么才适合?
脸上过敏反反复复。这是为什么呢?要吃些什么才适合?
病情描述:
很怕有什么问题脸上过敏反反复复,怎么回事儿呢,怎么办
医生提醒:微信加医生为好友,快速帮您诊断
已回答68557条
医生建议:你的情况我建议你用(新芙健),用于过敏性皮炎、亚急性慢性湿疹、阴囊湿疹、和等可以服用抗过敏药物进行治疗的,如扑尔敏
(不少于10个中文字符)
直购热线:400-
可能相关的药品
向专家医生提问专业医生在线,十分钟内快速回复!
请输入您的问题
看过本问题的人还看过
就诊科室:
病变部位:
典型症状:
混淆疾病:
相关用药指导
相关健康资讯
相关治疗医生
杨玉峰&主任医师深圳市中医院皮肤科
刁友涛&副主任医师广东省妇幼保健院皮肤性病
蔡希&主任医师上海市中医医院外科
吴菊生&主任医师上海市中医医院外科
田蓉&副主任医师中国人民解放军空军总医院皮肤科
徐娟&副主任医师深圳市第四人民医院皮肤性病
相关治疗医院
医院地区等级
保健养生热门问答
保健养生专业医生在线
已帮助 5672896 位患者
相关疾病问题
【新霉素氟轻松乳膏(恒健)】
【慢性湿疹】
【肛周慢性湿疹】
小儿七星茶颗粒:开...
健客价:¥30.00
补气,滋肾,益精,用...
健客价:¥48.00
乳酸菌素片(天安堂)...
健客价:¥29.00
补气,滋肾,益精。用...
健客价:¥345.00
健客价:¥11,440.00
润肺止咳,理气化痰。...
健客价:¥30.00
配合饮食控制治疗Ⅱ型...
健客价:¥63.00
清湿热,凉血。
健客价:¥7.00
增强免疫力。
健客价:¥15.00
1.高血压。
健客价:¥30.00最近嘴角干燥皲裂有些痒,不知道是什么原因?
提示:疾病因人而异,网络上的资料不一定适合你,可在线咨询医生获取专属治疗方案。去了解
脸上过敏反反复复,最近嘴角干燥皲裂有些痒,之前好了一点有一天起床发现破皮了。不知道是什么原因,最近嘴角就还是起皮和痒还红红的。请问医生我是怎么回事?(女,21岁)
Your browser does not support the audio element.
鉴于等候时间很长后,您一直没有新补充和问题,我们将关闭此次咨询。请给予五星评价!如还有补充或新的咨询,请新开咨询问题发问即可!
微信关注医生
擅长:疱疹、梅毒、尖锐湿疣、艾滋病、性病、真菌感染
已有 563 人关注
截图或保存上方二维码图片至手机相册 > 打开微信扫一扫 > 点击右上角“相册” > 选择本图片

我要回帖

更多关于 感冒反反复复老不好 的文章

 

随机推荐