成功接收几个小时后,UART接收中断停止触发 [英] UART receive interrupt stops triggering after several hours of successful receive

查看:101
本文介绍了成功接收几个小时后,UART接收中断停止触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用与xbee连接的STM32f4发现板来接收来自远程温度传感器的温度数据.使用的代码是CMIS UART示例代码.我将一次接收一个字节的数据包数据.换句话说,每当接收到每个字节时,都会调用UART接收中断.一旦获得完整的数据包,我将复制温度数据.我的UART回调函数可以正常工作.但是几个小时后,UART接收中断停止工作,并且UART无法接收任何东西.但是,UART传输仍然有效.我正在使用波特率为115200的UART1.我已将UART中断优先级设置为0,并且没有其他中断共享该优先级.所有其他中断优先级均低于UART.谁能告诉我为什么UART中断停止触发?

I am using STM32f4 discovery board connected with xbee to receive temperature data from remote temperature sensor. Code used is CMIS UART example code. I will receive packet data, 1 byte at a time. In other words UART receive interrupt will be called whenever each byte receives. Once I gets the complete packet I will copy the temperature data. My UART callback function works without any issue. But after several hours, UART receive interrupt stops working and UART cannot receive anything. However UART transmission still works. I am using UART1 with baud rate 115200. I have set UART interrupt priority as 0 and no other interrupt shares this priority. All other interrupt priority are lower than UART. Can any one please tell me why UART interrupt stops triggering?

#define PACKET_DELIMETER 0x7E

uint8_t g_frame_ok=0; //flag to indicate complete packet received
uint8_t g_index_of_aoBuf=0; //Index of receive buffer
uint8_t g_aoBuf_of_xbee[100]={0};//Receive Buffer
uint8_t r_byte=0; //Receiving byte 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *allUartHandle)
{
 __HAL_UART_FLUSH_DRREGISTER(allUartHandle); 

 if(HAL_UART_Receive_IT(allUartHandle, (uint8_t *)&r_byte, 1) == HAL_OK) //Interrupt occurs when each byte arrives
 {
    if(r_byte==PACKET_DELIMETER)
    {
        //start receiving packet
    }
    if( g_index_of_aoBuf>=g_aoBuf_of_xbee[2]+4)
    {
        g_frame_ok=1;
        BSP_LED_On(LED4);
    }           
   }
 }

推荐答案

我从未使用过您提到的API,所以我可能是错的,但是以下是我看过后发现的一些内容:

I never used the API you mention, so I may be wrong, but here are a few things I noticed after taking a look :

HAL_UART_RxCpltCallback 不是UART中断.这是HAL子系统的回调,当您发出的接收请求完成时将调用该回调.这意味着它只会在您发出接收请求后的某个时间被调用.您无权访问UART中断,并且如果使用HAL层,也不要试图弄乱它.

HAL_UART_RxCpltCallback is not an UART interrupt. It's a callback from the HAL subsystem that will be called when a receive request you issued is completed. This means it will only be called some time after you issue a receive request. You don't have access to the UART interrupt, and you shouldn't try to mess with it if you use the HAL layer.

关于此, HAL_UART_Receive_IT 实际上是一个将发出接收请求的函数.它总是会立即返回,并且永远不会收到任何东西.这意味着在调用之后接收缓冲区中的数据无效.发出请求后,将在接收完成后的任何时间调用 HAL_UART_RxCpltCallback .仅在这一点上,缓冲区中的数据才有效.要检索数据,可以使用 HAL_UART_Receive_IT 中的相同变量,但是数据缓冲区也可以通过回调参数中的(UART_HandleTypeDef *)-> pRxBuffPtr 使用.

About this, HAL_UART_Receive_IT is actually a function that will issue a receive request. It will always return immediately, and it will never receive anything. This means the data in the receive buffer just after the call is not valid. Once you issued the request, HAL_UART_RxCpltCallback will be called anytime after, when the receive is complete. Only at this point the data in the buffer will be valid. To retrieve the data you can use the same variable from the HAL_UART_Receive_IT, but the data buffer will also be available through (UART_HandleTypeDef*)->pRxBuffPtr from the callback parameter.

我认为在回调中再次调用 HAL_UART_Receive_IT 是可以的,但最后最好这样做.

I think it's OK to call HAL_UART_Receive_IT again in the callback, but it's probably better to do it at the end.

此外, __ HAL_UART_FLUSH_DRREGISTER 用于什么?在我看来,这样做弊大于利.

Also, what is __HAL_UART_FLUSH_DRREGISTER used for ? To me it looks like it will do more harm than good.

这篇关于成功接收几个小时后,UART接收中断停止触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆