STM32 HAL库 串口中断方式发送接收数据

发送和接收两个函数

  /*##-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.csdn.net/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库 串口中断方式发送接收数据)