相邻两帧之间的时间1s,应该足够mcu解析。1. 可以考虑DMA接收结合空闲中断,库函数如下,鉴于每一帧字节数目可能变动,所以DMA传输的字节要最大,因此,退出条件或者是接收到规定数目字节的数据或者Rx空闲。 /** * @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. */ }
所在话题
参与活动
-
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16