×
单片机 > 单片机程序设计 > 详情

STM32 HAL库 串口DMA发送完成中断

发布时间:2020-05-28 发布时间:
|

近期使用STM32驱动MAX3485进行485通信,发现STM32F103C8并不自带硬件485首发功能,需要软件上控制IO高低来驱动MAX3485进行485接收、485发送。

根据MAX3485手册可得,进行485发送时给相应引脚高电平。其余时间为低电平进行485接收。因此需要找到串口DMA发送完成的回调函数,在发送完成后将引脚拉低。

在stm32f1xx_hal_uart.c中


/** @defgroup UART_Exported_Functions_Group2 IO operation functions 

  *  @brief UART Transmit and Receive functions 

  *

@verbatim

  ==============================================================================

                      ##### IO operation functions #####

  ==============================================================================

  [..]

    This subsection provides a set of functions allowing to manage the UART asynchronous

    and Half duplex data transfers.


    (#) There are two modes of transfer:

       (++) Blocking mode: The communication is performed in polling mode. 

            The HAL status of all data processing is returned by the same function 

            after finishing transfer.  

       (++) Non blocking mode: The communication is performed using Interrupts 

            or DMA, these APIs return the HAL status.

            The end of the data processing will be indicated through the 

            dedicated UART IRQ when using Interrupt mode or the DMA IRQ when 

            using DMA mode.

            The HAL_UART_TxCpltCallback(), HAL_UART_RxCpltCallback() user callbacks 

            will be executed respectively at the end of the transmit or receive process.

            The HAL_UART_ErrorCallback() user callback will be executed when 

            a communication error is detected.


    (#) Blocking mode APIs are:

        (++) HAL_UART_Transmit()

        (++) HAL_UART_Receive() 


    (#) Non Blocking mode APIs with Interrupt are:

        (++) HAL_UART_Transmit_IT()

        (++) HAL_UART_Receive_IT()

        (++) HAL_UART_IRQHandler()


    (#) Non Blocking mode functions with DMA are:

        (++) HAL_UART_Transmit_DMA()

        (++) HAL_UART_Receive_DMA()

        (++) HAL_UART_DMAPause()

        (++) HAL_UART_DMAResume()

        (++) HAL_UART_DMAStop()


    (#) A set of Transfer Complete Callbacks are provided in non blocking mode:

        (++) HAL_UART_TxHalfCpltCallback()

        (++) HAL_UART_TxCpltCallback()

        (++) HAL_UART_RxHalfCpltCallback()

        (++) HAL_UART_RxCpltCallback()

        (++) HAL_UART_ErrorCallback()


    [..]

      (@) In the Half duplex communication, it is forbidden to run the transmit 

          and receive process in parallel, the UART state HAL_UART_STATE_BUSY_TX_RX

          can't be useful.


可以看到 HAL_UART_TxCpltCallback() 的相关解释,发现其位发送完成的回调函数。

因此定义该函数后自行添加相关的代码即可完成。

关键字:STM32  HAL库  串口DMA  中断 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
51单片机中断源的扩展方法