/**
* @brief put char to the Tx Buffer
将来自printf的数据写入Buffer,
* @param None
* @retval None
* @by WWW.ARMJISHU.COM
*/
void USART_StoreBufferData(uint8_t ch)
{
while(TxCounter == USART_TX_DATA_SIZE);
if(TxCounter < USART_TX_DATA_SIZE)
{
/* Write one byte to the transmit data register */
USART_Tx_Buffer[USART_Tx_ptr_Store++] = ch;
USART_Tx_ptr_Store = USART_Tx_ptr_Store & 0xFF;
TxCounter++;
}
USART_ITConfig(EVAL_COMx, USART_IT_TXE, ENABLE);
}
在这个函数里只是把变量ch传到了USART_TX_Buffer中并在下面使能了串口发送中断并没有触发。
void USARTx_IRQHandler(void)
{
if (USART_GetITStatus(USARTx, USART_IT_RXNE) != RESET)
{
/* received data */
USART_GetInputString();
}
/* If overrun condition occurs, clear the ORE flag
and recover communication */
if (USART_GetFlagStatus(USARTx, USART_FLAG_ORE) != RESET)
{
(void)USART_ReceiveData(USARTx);
}
if(USART_GetITStatus(USARTx, USART_IT_TXE) != RESET)
{
/* Write one byte to the transmit data register */
}
这是串口中断处理函数里面调用了一个发送函数 USART_SendBufferData();
void USART_SendBufferData(void)
{
if(TxCounter > 0)
{
/* Write one byte to the transmit data register */
USART_SendData(EVAL_COMx, USART_Tx_Buffer[USART_Tx_ptr_Out++]);
TxCounter--;
USART_Tx_ptr_Out = USART_Tx_ptr_Out & 0xFF;
}
else
{
/* Disable the EVAL_COM1 Transmit interrupt */
USART_ITConfig(EVAL_COMx, USART_IT_TXE, DISABLE);
}
}