由于函数较多和过长的缘故,下面仅以HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)为例,分析源码:
/**
* @brief Sends an amount of data in non blocking mode.
* @param huart: pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @param pData: Pointer to data buffer
* @param Size: Amount of data to be sent
* @retval HAL status
*/ 串口中断发送,以中断方式发送指定长度的数据。
HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
/* Check that a Tx process is not already ongoing */
if(huart->gState == HAL_UART_STATE_READY) 如果 串口空闲,则执行以下语句。
{
if((pData == NULL ) || (Size == 0U)) 如果发送数据为空或者发送长度为0,则返回错误。
{
return HAL_ERROR;
}