/**
* @brief Receives an amount of data in non blocking mode.
* @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
* the received data is handled as a set of u16. In this case, Size must indicate the number
* of u16 available through pData.
* @param huart Pointer to a UART_HandleTypeDef structure that contains
* the configuration information for the specified UART module.
* @param pData Pointer to data buffer (u8 or u16 data elements).
* @param Size Amount of data elements (u8 or u16) to be received.
* @retval HAL status
*/
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
首先思考一个问题:这个函数是会以中断方式来接受字符串的,那么每次接受一个字符就一定会发生一次中断,那么这个函数里面的size是给来干什么的?用来判断是否接受完成的。但是这个逻辑需要我们自己去设计例如:
在中断处理函数里面:
void USART1_IRQHandler(void)
{
HAL_UART_IRQHandler(&huart1);
HAL_UART_Receive_IT(&huart1,(uint8_t*)&goodBuffer[order],1);
}
可以加入一下判断是否接受完成的代码:
int order=0;
int size=5;
void USART1_IRQHandler(void)
{
HAL_UART_IRQHandler( &huart1);
order++;
if(order==size-1)//这个时候就接受完成了
{
//其他代码
}
HAL_UART_Transmit(&huart1,(uint8_t*)goodBuffer,sizeof(goodBuffer),0xffff);
HAL_UART_Receive_IT(&huart1,(uint8_t*)&goodBuffer[order],1);
}