如上图所示,外部大约间隔1s左右传输一帧数据过来,正常情况下是一帧5个字节.如果采用接收中断的方式接收数据HAL_UART_Receive_IT(&huart1, (uint8_t *)&Uart1_Rxdata, 5); 假如数据正常传输过程种,中间突然出现了一帧数据为4个字节,那处理器会丢掉这一帧数据吗? 还是将这一帧4个字节 + 下一帧的第一个字节 组成5个字节的数据,产生接收中断? 再假如数据正常传输过程种,中间突然出现了一帧数据为6个字节,那处理器会丢掉这一帧数据吗? 还是将这一帧数据的前5个字节一起产生接收中断,剩下一个字节丢弃? |
STM32G070RBT6 我将PA14-BOOT0改为USART2RX,
STM32CubeIde生成的工程,使用printf函数没有调用_write函数
STM32F767IGx 使用串口模块正常运行串口不能接收,debug模式正常。
stm32G0B1RCT6在串口快速收发时导致中断服务函数无法进入
在FreeRTOS中串口重定向使用HAL库函数中断出现异常
stm32f407 开启两路(FS和HS) Custom HID,与上位机通信偶尔中断
stm32f746g-disco开发板的串口通讯连接方式
usart奇偶校验问题
总线舵机驱动电路的一部分求解读
采用USB 全速CDC的时候(12M 波特率),motor pilot的串口速度可以设置为多少,能设置成7372800吗
首先非常感谢您的耐心解答,我也看了一些空闲中断的介绍文档,但是没有用过这种方式,还有一点儿疑问。我的硬件是STM32f405,工作频率168M,有两路串口要不停的接收帧协议数据,每一帧7个字节,波特率是2M,数据量应该是特别大的,因为我需要解析帧协议,所以想采用单字节接收中断的方式,也就是HAL_UART_Receive_IT(&huart1,(uint8_t *)&Uart1_Rxdata, 1); 这种方式是不是不太好,不是最佳的方式?是不是会让CPU负担很重?如果是的话,能通过什么方式可以测出CPU现在负担有多重?(是不是可以通过在中断回调函数的起始和终点处设置IO电平翻转来看中断函数执行时间和频率,去确定CPU当前的负担?)
对于我这种2M波特率,需要帧协议解析(帧长度固定)的情况,最佳的方式是?
/**
* @brief Receive an amount of data in DMA mode till either the expected number
* of data is received or an IDLE event occurs.
* @note Reception is initiated by this function call. Further progress of reception is achieved thanks
* to DMA services, transferring automatically received data elements in user reception buffer and
* calling registered callbacks at half/end of reception. UART IDLE events are also used to consider
* reception phase as ended. In all cases, callback execution will indicate number of received data elements.
* @note When the UART parity is enabled (PCE = 1), the received data contain
* the parity bit (MSB position).
* @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
* the received data is handled as a set of uint16_t. In this case, Size must indicate the number
* of uint16_t available through pData.
* @param huart UART handle.
* @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
* @param Size Amount of data elements (uint8_t or uint16_t) to be received.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef status;
(略)
2. 回调函数如下,其中返回Size为实际接收到的数据,接收缓冲从0到Size-1就是数据,解析协议应该在这里执行。
/**
* @brief Reception Event Callback (Rx event notification called after use of advanced reception service).
* @param huart UART handle
* @param Size Number of data available in application reception buffer (indicates a position in
* reception buffer until which, data are available)
* @retval None
*/
__weak void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
UNUSED(Size);
/* NOTE : This function should not be modified, when the callback is needed,
the HAL_UARTEx_RxEventCallback can be implemented in the user file.
*/
}