你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

st-img
chrome
st-img
firefox
st-img
safari
st-img
ie8及以上
shequ.stmicroelectronics.cn
  • ST意法半导体官网
  • STM32中文官网
  • ST全球论坛
登录/注册
  • 首页
  • 技术问答
  • 话题
  • 资源
  • 创客秀
  • 视频
  • 标签
  • 积分商城
  • 每日签到
zhong5411

zhong5411

 

回答数 0 关注数 0
关注 私信
  • 动态99
  • 提问
  • 回答0
  • 创客秀 0
  • 分享 0
  • 关注0
5 回答

STM32串口接收中断疑问 求解?

串口 UART
yr yr 回答时间: 2021-8-13 15:45

相邻两帧之间的时间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.    */ }

赞0
zhong5411 zhong5411


阅读作者更多的帖子

所在话题

参与活动

  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    网络 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16
  • 滴滴押注社区团购,明确“投入不设上限,要做市场第一”

    线下 2020-10-16