发送和接收两个函数
/*##-2- Start the transmission process #####################################*/
/* While the UART in reception process, user can transmit data through
"aTxBuffer" buffer */
if(HAL_UART_Transmit_IT(&UartHandle, (uint8_t*)aTxBuffer, TXBUFFERSIZE)!= HAL_OK)
{
Error_Handler();
}
/*##-3- Wait for the end of the transfer ###################################*/
while (UartReady != SET)
{
}
/* Reset transmission flag */
UartReady = RESET;
/*##-4- Put UART peripheral in reception process ###########################*/
if(HAL_UART_Receive_IT(&UartHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
Error_Handler();
}
下面是zhon重点:::::
开始我以为这两个只是中断发送和中断接收函数,原来还有使能发送中断和接收zh中断的作用,如果不执行这两个函数,就不会使能发送中断或接收中断,从而下面这两个回调函数的内容就不会执行,尤其是接收中断,执行一次后要再zhi'执行一次HAL_UART_Receive_IT这个函数,才能再次启用接收中断
谢谢这篇文章的作者:
https://blog.youkuaiyun.com/ouening/article/details/79218971
@brief ·¢ËÍÍê³ÉÖжϻص÷º¯ÊýTx Transfer completed callback
* @param UartHandle: UART handle.
* @note This example shows a simple way to report end of IT Tx transfer, and
* you can add your own implementation.
* @retval None
*/
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
/* Set transmission flag: transfer complete */
UartReady = SET;
LED1_OFF();
}
/**
* @brief ½ÓÊÕÍê³ÉÖжϻص÷º¯ÊýRx Transfer completed callback
* @param UartHandle: UART handle
* @note This example shows a simple way to report end of DMA Rx transfer, and
* you can add your own implementation.
* @retval None
*/
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
//uint8_t* pc;
//uint8_t ch = 0;
本文介绍了如何使用STM32的HAL库进行串口中断方式的数据发送和接收。通过调用HAL_UART_Transmit_IT和HAL_UART_Receive_IT函数,不仅可以实现数据的发送和接收,还能启用中断,使得发送完成和接收完成时能够触发相应的回调函数。当发送或接收完成后,需要重置标志位以重新启用中断。
7234

被折叠的 条评论
为什么被折叠?



