近期使用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() 的相关解释,发现其位发送完成的回调函数。
因此定义该函数后自行添加相关的代码即可完成。
上一篇:基于HAL库处理UART中断并接收串口传入的数据
下一篇:关于烈火四轴遥控器串口上传分析
推荐阅读最新更新时间:2024-10-28 23:14
设计资源 培训 开发板 精华推荐
- 泰克完整LED驱动测试方案 领跑节能亮化新时代
- 报名有好礼!50元京东卡等您拿!
- 关注 PI 最新 SCALE-iDriver IC产品系列 答题有好礼!
- 《看一个TI老工程师如何驯服精密放大器》点评有礼!
- 有奖直播报名中|基于英飞凌AIROC™ CYW20829低功耗蓝牙芯片的无线组网解决方案
- 造个车,一起驶向诗和远方!学习 TI 汽车参考设计,参加技能小测试赢好礼!
- 有奖直播:英飞凌针对电动工具的高功率、高效率以及高可靠性解决方案
- 有奖直播已结束【如何利用 TI MSPM0 汽车微控制器提高检测和控制性能】
- 有奖活动 | 来 Pl BridgeSwitch™ 技术中心探秘半桥电机驱动器新技术
- 【我提问,你回答】你敢参与不?