HAL库对中断方式封装的太厉害,要添加自己的东西非常不方便,虽然有回调函数,但是都是固定的那几种状态。
1、代码中使能硬件FIFO
void bsp_InitUart(void)
{
/*##-1- 配置串口外设 ######################################*/
/* USART3工作在UART模式 */
/* 配置如下:
- 数据位 = 8 Bits
- 停止位 = 1 bit
- 奇偶校验位 = 无
- 波特率 = 115200bsp
- 硬件流控制 (RTS 和 CTS 信号) */
UartHandle.Instance = USART3;
UartHandle.Init.BaudRate = 115200;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
UartHandle.Init.Prescaler = UART_PRESCALER_DIV1;
UartHandle.Init.FIFOMode = UART_FIFOMODE_ENABLE;
UartHandle.Init.TXFIFOThreshold = UART_TXFIFO_THRESHOLD_3_4;
UartHandle.Init.RXFIFOThreshold = UART_RXFIFO_THRESHOLD_3_4;
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if(HAL_UART_DeInit(&UartHandle) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
if(HAL_UART_Init(&UartHandle) != HAL_OK)
{
Error_Handler(__FILE__, __LINE__);
}
}
2、使用串口中断方式发送的话,在函数HAL_UART_Transmit_IT里面使能FIFO中断
/* Enable the TX FIFO threshold interrupt (if FIFO mode is enabled) or
Transmit Data Register Empty interrupt (if FIFO mode is Disabled).
*/
if (READ_BIT(huart->Instance->CR1, USART_CR1_FIFOEN) != RESET)
{
SET_BIT(huart->Instance->CR3, USART_CR3_TXFTIE);
}
else
{
SET_BIT(huart->Instance->CR1, USART_CR1_TXEIE);
}
接收函数 HAL_UART_Receive_IT里面的FIFO使能中断
/* Enable the UART Parity Error interupt and RX FIFO Threshold interrupt
(if FIFO mode is enabled) or Data Register Not Empty interrupt
(if FIFO mode is disabled).
*/
if (READ_BIT(huart->Instance->CR1, USART_CR1_FIFOEN) != RESET)
{
SET_BIT(huart->Instance->CR1, USART_CR1_PEIE);
SET_BIT(huart->Instance->CR3, USART_CR3_RXFTIE);
}
else
{
SET_BIT(huart->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
}
3、进入中断函数里面,发现全程无处理函数,HAL_UART_IRQHandler,看来只能自己写了。 |